note 62341 added to function.sort
| From: | ludvigdotericsonatgmaildotcom at osu1 dot php dot net | Date: | Sat, 25 Feb 2006 17:48:58 +0000 |
| Subject: | note 62341 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-104428@lists.php.net to get a copy of this message | ||
A tip for those who like "raul at jimi dot com dot mx" need to preserve keys after
changing stuff in the middle of an array:
array_values.
Example:
<?php
$array = array(1, 2, 5, 9, 3);
unset($array[3]); // Remove index 3, which is 9.
$array = array_values($array);
?>
Hint: array_values can be fine for removing keys and reindex them by number instead, too (applies to
functions like posix_pwgetuid which returns an associative array, unlike C and others, call
array_values on it, and it'll be the same format IIRC.)
----
Server IP: 129.16.214.50
Probable Submitter: 213.89.140.136
----
Manual Page -- http://www.php.net/manual/en/function.sort.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+62341
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62341&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62341&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62341&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62341&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62341&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62341&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62341&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+62341&report=yes
Search -- http://master.php.net/manage/user-notes.php