PHP commonly used array manipulation functions

We have many elements that operate on arrays, let’s talk about some of them first in this section. In 6.3 we will summarize more common array functions.

The following functions are mainly used to move the array pointer and push in and pop out array elements.

array_shift

##mixed array_shift ( array &$array )


QQ截图20161114134130.png

array_unshift

int array_unshift (array &$array, mixed $value 1 [, mixed $... ] )

QQ截图20161114134218.png

array_pop

mixed array_pop (array &$array)


QQ截图20161114134302.png

array_push

Function: Push one or more elements to the end of the index array, and return the total number.

'; print_r($mingren); ?>

Execution result:


QQ截图20161114134336.png

The functions of these functions have been explained very clearly. We demonstrate through code:


Continuing Learning
||
'永远', 'dbg'=>'需要不断奋进', 'djn'=>'才能开创未来' ); //读取数组的值 echo current($t).'
'; //读取数组的键 echo key($t).'
'; //向后移动一下 next($t); //再读值和键 echo current($t).'
'; echo key($t).'
'; //向后移动一下 next($t); echo current($t).'
'; echo key($t).'
'; //向前移动一下 prev($t); echo current($t).'
'; echo key($t).'
'; //移到末尾 end($t); echo current($t).'
'; echo key($t).'
'; //移至开始处 reset($t); echo current($t).'
'; echo key($t).'
'; //销毁数组 unset($t); var_dump($t); ?>
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
##array_shift Pop array The first element in array_unshift Push the element at the beginning of the array array_push Push elements to the end of the array array_pop Pop the last element at the end of the array current Read the value of the current position of the pointer #key Read the key of the current position of the pointer next Move the pointer down prev Move up reset Pointer to the beginning end Pointer to the end Function: Pop the first element in the array
'; print_r($mingren); ?>
Execution result:Conclusion:1. Pop out the first array element, changing the result of the original array2. The pop-up value is assigned to $dcFunction: Push one or more elements to the beginning of the index array, and return the total number.
'; print_r($mingren); ?>
The execution results are as follows:Function: pop up an element at the end of the array
'; print_r($mingren); ?>
Execution result:##int array_push ( array &$array , mixed $value1 [, mixed $... ] )#current,key,prev,next,reset function demonstration
'永远', 'dbg'=>'需要不断奋进', 'djn'=>'才能开创未来' ); //读取数组的值 echo current($t).'
'; //读取数组的键 echo key($t).'
'; //向后移动一下 next($t); //再读值和键 echo current($t).'
'; echo key($t).'
'; //向后移动一下 next($t); echo current($t).'
'; echo key($t).'
'; //向前移动一下 prev($t); echo current($t).'
'; echo key($t).'
'; //移到末尾 end($t); echo current($t).'
'; echo key($t).'
'; //移至开始处 reset($t); echo current($t).'
'; echo key($t).'
'; //销毁数组 unset($t); var_dump($t); ?>
Function Function