<?PHP $arr=array(1,2,3,4,5,6,7,8,9); $ret=array_pop($arr); echo "$ret"; //9 foreach($arr as $element) echo "$element, "; //1, 2, 3, 4, 5, 6, 7, 8, ?>
However, if the array is an associative array, only the value will be returned.
<?PHP $arr = array("one"=>"Monday","two"=>"Tuesday","three"=>"Wednesday", "four"=>"Thursday","five"=>"Friday","six"=>"Saturday","seven"=>"Sunday"); $elem = array_pop($arr); echo "$elem"; //the result is Sunday ?>
The following code will return the last key, value pair of the specific associative array, and remove the last key, value pair from the array as well.
<?PHP $arr = array("one"=>"Monday","two"=>"Tuesday","three"=>"Wednesday", "four"=>"Thursday","five"=>"Friday","six"=>"Saturday","seven"=>"Sunday"); $elempair = [array_key_last($arr) => array_pop($arr)]; ?>