Arrays in PHP are often used as stacks (LIFO: LIFO) with the queue (first-out: FIFO) structure. PHP provides a set of functions that can be used for push with pop (stack) and shift with Unshift (queue) to manipulate array elements. Stacks and queues are widely used in practice.
We can look at the stack first:
Copy CodeThe code is as follows:
$arr = Array ();
Array_push ($arr, ' AAA ');
Array_push ($arr, ' BBB ');
$arr. Pop ();
Print_r ($arr);
?>
If you intend to use the array as a queue (FIFO), you can use Array_unshift () to add elements, using Array_shift () to delete:
Copy CodeThe code is as follows:
$arr = Array ();
Array_unshift ($arr, ' AAA ');
Array_unshift ($arr, ' BBB ');
Print_r ($arr);
Array_shift ($arr);
Print_r ($arr);
?>
http://www.bkjia.com/PHPjc/327789.html www.bkjia.com true http://www.bkjia.com/PHPjc/327789.html techarticle Arrays in PHP are often used as stacks (LIFO: LIFO) with the queue (first-out: FIFO) structure. PHP provides a set of functions that can be used for push vs. Pop (stack) and shift with ...