PHP array_shift pops the first element of the array
PHP array_shift is used to pop the first element of the array, for example, an array with five elements originally, after processing through array_shift, the original first array element will disappear, and the original second element will be filled forward and become a new one In the first position, array_shift can only be used to process Arrays, not general strings.
PHP array_shift syntax example
array_shift (array waiting to be processed);
PHP array_shift will pop the first array element and reduce the length of the array by one. The original sequence is filled forward to become a new array. That is to say, the new array processed by array_shift has the same key number starting from 0, but the key value is different from the original array. If you want to deal with the array itself is an empty array or not an array, return NULL.
PHP array_shift implementation example
$Arr=array('A','B' ,'C','D' );
$Str = array_shift ($Arr );
print_r( $Arr );
?>
At the beginning of the example, a four-element array $Arr is prepared. Through array_shift processing in the second row, the first When an element A is bounced off, the A that pops up is handed over to $Str. The last line uses print_r to output the processed $Arr. Obviously, there are only three elements left, and the key value of all elements is one digit forward.
Post a Comment
0 Comments