note 25098 deleted from ref.array by sniper

From: Date: Sat, 18 Oct 2003 18:03:59 +0000
Subject: note 25098 deleted from ref.array by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58841@lists.php.net to get a copy of this message
Note Submitter: J. Dyer (jkdyer_at_vlsmaps_dot_com) ---- As it has been stated before, array_pop and the splice-derived functions re-index any associatively defined elements.. // bad array example $array[5] = "foo"; $array[6] = "bar"; $var = array_pop($array); $key = key($array); // $key would be 0, not 5 as would be expected for the value "foo". Instead, keep your keys/associations by using the unset() function. // better array example end($array); $key = key($array); unset($array[$key]); // now the other keys/values aren't touched. ... This will remove the last entry in your array, but not re-index it. In this manner, you won't lose your associations. It has been tested and seems to work fine.

« previous php.notes (#58841) next »