note 110942 added to function.sort
| From: | me | Date: | Thu, 27 Dec 2012 12:36:18 +0000 |
| Subject: | note 110942 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192687@lists.php.net to get a copy of this message | ||
Sorting the keys, but keep the values in order is not possible by just ordering, because it would
result in a new array. This is also the solution: Create a new array
<?php
$a = array(9=>"a",8=>"c",5=>"d");
$keys = array_keys($a);
sort($keys);
$result = array_combine($keys, array_values($a));
//Result : array(5=>"a",8=>"c",9=>"d");
?>
----
Server IP: 69.147.83.199
Probable Submitter: 91.64.180.142
----
Manual Page -- http://php.net/manual/en/function.sort.php
Edit -- https://master.php.net/note/edit/110942
Del: integrated -- https://master.php.net/note/delete/110942/integrated
Del: useless -- https://master.php.net/note/delete/110942/useless
Del: bad code -- https://master.php.net/note/delete/110942/bad+code
Del: spam -- https://master.php.net/note/delete/110942/spam
Del: non-english -- https://master.php.net/note/delete/110942/non-english
Del: in docs -- https://master.php.net/note/delete/110942/in+docs
Del: other reasons-- https://master.php.net/note/delete/110942
Reject -- https://master.php.net/note/reject/110942
Search -- https://master.php.net/manage/user-notes.php