note 30610 added to function.sort
| From: | matias at arenasoftware dot com | Date: | Sun, 23 Mar 2003 23:36:29 +0000 |
| Subject: | note 30610 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45706@lists.php.net to get a copy of this message | ||
Lets say you have the following array:
$array1 = Array(third => "Some text 3", second => "Some text 2", first
=> "Some text 1", fourth => "Some text 4" );
and you want to sort it by first,second,third, fourth.
Very easy! Just create a second array:
$array2 = Array(first => "", second => "", third => "",
fourth => "");
and do:
$result = array_merge($array2,$array1);
now $result = Array(first => "Some text 1",second => "Some text 2",third
=> "Some text 3",fourth => "Some text 4");
This is very usefull when you want to print data out of a database table for example, but you would
like to give it a custom order.
--
http://www.php.net/manual/en/function.sort.php
http://master.php.net/manage/user-notes.php?action=edit+30610
http://master.php.net/manage/user-notes.php?action=delete+30610
http://master.php.net/manage/user-notes.php?action=reject+30610