PHP array_shift () Application

the array_shift () the beginning of the array out of the array element, and returns as a result, the array length minus one forward movement and one for all other units. All digital keys will instead start counting from zero character keys will not change. If the array is null or not an array NULL is returned. Note: If a large amount of elements, this operation can be time consuming, because the index to be recalculated, the time complexity is O (n); improved process is to use array_reverse (), then array_pop ().

Simple examples are as follows:

$arr = array('a','b','c','d','e');
print_r($arr);
$arr1 = array_reverse($arr);
print_r($arr1);
array_pop($arr1);
print_r($arr1);
$arr = array_reverse($arr1);
print_r($arr);

 

Guess you like

Origin blog.csdn.net/uvyoaa/article/details/84588900