PHP implements queues using arrays
- 2020-05-12 02:21:32
- OfStack
PHP treats the array as a stack, primarily using the system functions array_push() and array_pop(). Pushing is basically adding one or more elements to the end of the first argument's array using the array_push() function, and then returning the length of the new array, as shown below:
In PHP, treating an array as a queue is implemented primarily with array_push() and array_shift().
Stack is mainly used to use the array_shift() function to pop up the first element of the array and subtract the length of the array by 1, as shown below:
In PHP, treating an array as a queue is implemented primarily with array_push() and array_shift().
<?php
$zhan=array("WEB");// The statement 1 Two arrays as a queue
array_push($zhan,"PHP");// Pushes a string onto a stack (array)
array_push($zhan,"WWW.CHHUA.COM");// To push the 1 An element
print_r($zhan);// Print array contents
?>
Stack is mainly used to use the array_shift() function to pop up the first element of the array and subtract the length of the array by 1, as shown below:
<?php
$zhan=array("WEB","www.chhua.com","WEB Development of notes ","PHP"," The website construction ");// The statement 1 Two arrays as a stack
array_shift($zhan);// To take a string out of an array
print_r($zhan);// Print array contents Array([0] => WEB[1] => www.chhua.com[2] => WEB Development of notes [3] => PHP)
?>