note 97498 added to function.array-pop

From: Date: Fri, 23 Apr 2010 02:27:30 +0000
Subject: note 97498 added to function.array-pop
Groups: php.notes 
Request: Send a blank email to php-notes+get-168532@lists.php.net to get a copy of this message
<?php // Retrieve the item by index and recalculate array index function array_pop_index(&$array, $index){ if( ! isset($array[$index]) ) return null; $temp = $array[$index]; unset($array[$index]); $array = array_values($array); return $temp; } // Retrieve the item by key and unset it (useful for associative arrays) function array_kpop(&$array, $key){ if(!isset($array[$key])) return null; $temp = $array[$key]; unset($array[$key]); return $temp; } // Use: $arr = array('bananas', 'lemons', 'oranges'); $str = array_pop_index($arr, 1); echo $str . "\n"; // output "lemons" print_r($arr); /* Output: Array ( [0] => bananas [1] => oranges ) */ $karr = array('one' => 'bananas', 'two' => 'lemons', 'three' => 'oranges'); $str = array_kpop($karr, 'one'); echo $str . "\n"; // output "bananas" print_r($karr); /* Output: Array ( [one] => bananas [three] => oranges ) */ ?> ---- Server IP: 69.147.83.197 Probable Submitter: 90.165.242.15 ---- Manual Page -- http://www.php.net/manual/en/function.array-pop.php Edit -- https://master.php.net/note/edit/97498 Del: integrated -- https://master.php.net/note/delete/97498/integrated Del: useless -- https://master.php.net/note/delete/97498/useless Del: bad code -- https://master.php.net/note/delete/97498/bad+code Del: spam -- https://master.php.net/note/delete/97498/spam Del: non-english -- https://master.php.net/note/delete/97498/non-english Del: in docs -- https://master.php.net/note/delete/97498/in+docs Del: other reasons-- https://master.php.net/note/delete/97498 Reject -- https://master.php.net/note/reject/97498 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168532) next »