Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array's in PHP LIFO or FIFO? [closed]

Tags:

php

I am new to PHP and wants to know whether array's in PHP are LIFO or FIFO. For e.g.

$var1 = array('1','2','3');
like image 539
mpirate Avatar asked Dec 02 '12 13:12

mpirate


2 Answers

They are what you make them :)

  • array_pop() removes an item off the end of an array (the last item that was added)

  • array_shift() removes the first item off the array (first one added).

So as you can see they are capable of behaving in both ways.

  • Last In First Out
  • First In First Out

It all depends on how you implement your code.

like image 122
Lix Avatar answered Nov 17 '22 04:11

Lix


Updated:

Well arrays are neither LIFO or FIFO. Actually, they are both IMO. ie. They can behave in both ways. You can make use of the available functions in php the either way (as required), as mentioned by Lix above.

like image 3
Viren Rajput Avatar answered Nov 17 '22 02:11

Viren Rajput