note 84179 added to function.array-shift

From: Date: Wed, 02 Jul 2008 12:15:26 +0000
Subject: note 84179 added to function.array-shift
Groups: php.notes 
Request: Send a blank email to php-notes+get-141064@lists.php.net to get a copy of this message
Just a useful version which returns a simple array with the first key and value. Porbably a better way of doing it, but it works for me ;-) <?php function array_kshift(&$arr) { list($k) = array_keys($arr); $r = array($k=>$arr[$k]); unset($arr[$k]); return $r; } // test it on a simple associative array $arr = array('x'=>'ball','y'=>'hat','z'=>'apple'); print_r($arr); print_r(array_kshift($arr)); print_r($arr); ?> Output: Array ( [x] => ball [y] => hat [z] => apple ) Array ( [x] => ball ) Array ( [y] => hat [z] => apple ) ---- Server IP: 69.147.83.197 Probable Submitter: 91.84.224.33 ---- Manual Page -- http://www.php.net/manual/en/function.array-shift.php Edit -- https://master.php.net/note/edit/84179 Del: integrated -- https://master.php.net/note/delete/84179/integrated Del: useless -- https://master.php.net/note/delete/84179/useless Del: bad code -- https://master.php.net/note/delete/84179/bad+code Del: spam -- https://master.php.net/note/delete/84179/spam Del: non-english -- https://master.php.net/note/delete/84179/non-english Del: in docs -- https://master.php.net/note/delete/84179/in+docs Del: other reasons-- https://master.php.net/note/delete/84179 Reject -- https://master.php.net/note/reject/84179 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#141064) next »