note 24803 added to function.end

From: Date: Wed, 28 Aug 2002 22:17:30 +0000
Subject: note 24803 added to function.end
Groups: php.notes 
Request: Send a blank email to php-notes+get-35949@lists.php.net to get a copy of this message
When adding an element to an array, it may be interesting to know with which key it was added. Just adding an element does not change the current position in the array, so calling key() won't return the correct key value; you must first position at end() of the array: function array_add(&$array, $value) { $array[] = $value; // add an element end($array); // important! return key($array); } -- http://www.php.net/manual/en/function.end.php http://master.php.net/manage/user-notes.php?action=edit+24803 http://master.php.net/manage/user-notes.php?action=delete+24803 http://master.php.net/manage/user-notes.php?action=reject+24803

« previous php.notes (#35949) next »