PHP array_pop pops the last element of the array

 PHP array_pop is used to cancel the last element in the array ( PHP Array ). For example, there are originally five array elements, and after processing through array_pop, only four array elements will remain. Array_pop can only be used to process Array and cannot be processed General string.


PHP array_pop syntax example
array_pop (array waiting to be processed);
array_pop will pop the last element of the array and reduce the length of the array by one, but if the array you are dealing with is an empty array, array_pop will only return NULL .

PHP array_pop implementation example
<?php
$Arr=array( 'A' ,'B' ,'C' , 'D' );
$Str=array_pop( $Arr );
print_r( $Arr);
?>
Output result: Array ([0] => A [1] => B [2] => C) In the

example, first prepare an array $Arr with four array elements, and then use array_pop to pop the last array element D Then use print_r to output the processed $Arr. Obviously, the output result has only three elements. So where did D go? In fact, the value of D has been given to the variable $Str, you can also try echo $Str to see it!

Post a Comment

0 Comments