note 59292 added to function.sort
| From: | raul at jimi dot com dot mx | Date: | Fri, 02 Dec 2005 05:50:27 +0000 |
| Subject: | note 59292 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99437@lists.php.net to get a copy of this message | ||
I had an array like this:
$arr=array (1,4,3,6,5);
which returns this:
$arr[0]=1
$arr[1]=4
$arr[2]=3
$arr[3]=6
$arr[4]=5
But lets say i remove [2] which is number 3, i get:
$arr[0]=1
$arr[1]=4
$arr[3]=6
$arr[4]=5
And i want to reindex without doing a sort because i dont want to lose the order of the numbers
(like a pop in a stack but in the middle of the list), i do this:
$arr=array_chunk($arr,count($arr));
$arr=$arr[0];
the result is:
$arr[0]=1
$arr[1]=4
$arr[2]=6
$arr[3]=5
This can be applied mostly for tree sorting, when you only have the id and the parent values of the
node, and you want to have N levels.
----
Manual Page -- http://www.php.net/manual/en/function.sort.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59292
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59292&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59292&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59292&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59292&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59292&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59292&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59292&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59292&report=yes
Search -- http://master.php.net/manage/user-notes.php