note 57234 added to ref.array
| From: | pol at osu1 dot php dot net | Date: | Tue, 27 Sep 2005 22:24:53 +0000 |
| Subject: | note 57234 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95899@lists.php.net to get a copy of this message | ||
Watch for strange behaviour when trying to delete by value in a integer-only array. For the
following function:
function my_array_delete_by_value($array, $value) {
$array_flip = array_flip($array);
if (isset($array[$array_flip[$value]]))
unset($array[$array_flip[$value]]);
return array_merge($array);
}
array(4) { [0]=> int(2) [1]=> int(5) [2]=> int(6) [3]=> int(8) }
returns
array(2) { [0]=> int(5) [1]=> int(8) }
ie deletes both element 2 and value 2.
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57234
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57234&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57234&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57234&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57234&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57234&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57234&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57234&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57234&report=yes
Search -- http://master.php.net/manage/user-notes.php