note 29950 added to function.current
| From: | retestro_REMOVE at SPAM_esperanto dot org dot il | Date: | Sun, 02 Mar 2003 00:31:33 +0000 |
| Subject: | note 29950 added to function.current | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44714@lists.php.net to get a copy of this message | ||
The docs do not specify this, but adding to the array using the brackets syntax:
$my_array[] = $new_value;
will not advance the internal pointer of the array. therefore, you cannot use current() to get the
last value added or key() to get the key of the most recently added element.
You should do an end($my_array) to advance the internal pointer to the end ( as stated in one of the
notes on end() ), then
$last_key = key($my_array); // will return the key
$last_value = current($my_array); // will return the value
If you have no need in the key, $last_value = end($my_array) will also do the job.
- Sergey.
--
http://www.php.net/manual/en/function.current.php
http://master.php.net/manage/user-notes.php?action=edit+29950
http://master.php.net/manage/user-notes.php?action=delete+29950
http://master.php.net/manage/user-notes.php?action=reject+29950