note 28552 added to function.array-shift

From: Date: Thu, 16 Jan 2003 18:00:44 +0000
Subject: note 28552 added to function.array-shift
Groups: php.notes 
Request: Send a blank email to php-notes+get-42229@lists.php.net to get a copy of this message
Here are some solutions on how to get not only the value but also the key of the 1st element of an associative array. - foreach ($myarray as $key => $value) { // use here $key, and $value as you want unset ($myarray[$key]); // if you want to get rid of the 1st element, as array_shift does break; } - $temporaryarray = array_keys ($myarray); $key = $temporaryarray[0]; $value = $myarray[$key]; unset ($myarray[$key]); // if you want to get rid of the 1st element or $value = array_shift ($myarray); // if you want to get rid of the 1st element - reset; // to be sure list ($key,$value) = each ($myarray); unset ($myarray[$key]); // if you want to get rid of the 1st element, as array_shift does Mathieu BOIS -- http://www.php.net/manual/en/function.array-shift.php http://master.php.net/manage/user-notes.php?action=edit+28552 http://master.php.net/manage/user-notes.php?action=delete+28552 http://master.php.net/manage/user-notes.php?action=reject+28552

« previous php.notes (#42229) next »