* Stacks and queues are the two most commonly used data structures. As for what stacks and queues are, it is beyond the course requirements.
* All you need to know now is that stacks and queues can quickly add elements to both ends of an array. The addition and deletion operations can be done
* The stack operation of the array: the addition and deletion of elements are only allowed at one end of the array
* 1. The tail
* 1. array_push(array, value1[,value2...): Push to the stack, return the new array number
* 2. array_pop(array): Pop the last element from the stack, the array length is reduced by 1
* 2. Header
* 1. array_unshift(array,value1[,value2...): Push to the stack and return the number of new arrays
* 2. array_shift(array): Pop the stack, pop the first element at the head, and the array length is reduced by 1
* Queue operation of the array: the addition and deletion of elements are allowed at both ends
* 1. Enter the tail into the queue, Head dequeue
* 1. array_push(array, value1[,value2...):Enqueue, return the number of new arrays
* 2. array_shift(array):Dequeue, Pop the first element in the head, and the array length is reduced by 1
* 2. The head is added to the queue, and the tail is dequeued
* 1. array_unshift(array,value1[,value2...) :Enqueue, return the new array number
* 2. array_pop(array): Dequeue, pop the last element, the array length is reduced by 1
* Note:
* 1. Added elements always appear as index elements, and multiple
can be added at the same time. * 2. Deletion can only pop up one element at a time.
* 3. Addition and deletion operations will cause the array pointer to be The reset operation reset()
echo '<pre class="brush:php;toolbar:false">'; $user = ['id'=>5,'name'=>'peter','gender'=>'male','age'=>30]; print_r($user); //查看数组 echo '<hr color="red">';
//First, simulate the stack operation: addition and deletion of elements are only allowed at one end
//1. array_push(array, value1[,value2.. .): Push the tail onto the stack, return the new array number
echo array_push($user, 'php中文网','www.php.cn'),'<br>'; print_r($user); //查看新成的数组
//2. array_pop(array): Pop the tail off the stack, pop the last element, and reduce the array length by 1
echo array_pop($user),'<br>'; print_r($user); //查看新成的数组
//Repeat An element is popped from the tail and has been restored to its original state
echo array_pop($user),'<br>'; print_r($user); //查看新成的数组
//3. array_unshift(array, value1[, value2...): Push the head onto the stack and return the new array number
echo array_unshift($user, 'php中文网','www.php.cn'),'<br>'; print_r($user); //查看新成的数组
//4. array_shift(array): Pop the head from the stack, pop the first element of the head, and reduce the array length by 1
echo array_shift($user),'<br>'; print_r($user); //查看新成的数组 echo array_shift($user),'<br>'; print_r($user); //查看新成的数组
//Second: Simulate queue operation: additions and deletions must be done at both ends , not allowed to be completed at the same end
// 1. array_push(array, value1[,value2...): The tail is added to the queue and the new array number is returned
echo array_push($user, 'php中文网','www.php.cn'),'<br>'; print_r($user); //查看新成的数组
// 2. array_shift (array): The head is dequeued, the first element of the head is popped out, and the array length is reduced by 1
echo array_shift($user),'<br>'; //出队的id=5这个元素,当然返回的只有值5 print_r($user); //查看新成的数组
// 3. array_unshift(array,value1[,value2...): The head is put into the queue, Return the number of new arrays
echo array_unshift($user, '华为','小米'),'<br>'; print_r($user); //查看新成的数组
// 4. array_pop(array): dequeue the tail, pop the last element, and reduce the array length by 1
echo array_pop($user),'<br>'; print_r($user); //查看新成的数组