note 104659 added to function.array-multisort
| From: | thierryzo at hotmail dot fr | Date: | Wed, 29 Jun 2011 09:27:40 +0000 |
| Subject: | note 104659 added to function.array-multisort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181031@lists.php.net to get a copy of this message | ||
//A very simple way to sort arrays with this kind of structure.
<?php
$myArray =array(
array("NUMCIE" => "001","REF" =>
"RXL","COLOR" => "RED","L1" => 4),
array("NUMCIE" => "001","REF" =>
"RXL","COLOR" => "BLUE","L1" => 6),
array("NUMCIE" => "001","REF" =>
"RHQ","COLOR" => "RED","L1" => 4),
array("NUMCIE" => "002","REF" =>
"RXL","COLOR" => "YELLOW","L1" => 8));
foreach($myArray as $c=>$key) {
$sort_numcie[] = $key['NUMCIE'];
$sort_ref[] = $key['REF'];
$sort_color[] = $key['COLOR'];
}
array_multisort($sort_numcie, SORT_ASC, $sort_ref, SORT_STRING, $myArray);
print_r($myArray);
?>
//Result array
Array
(
[0] => Array
(
[NUMCIE] => 001
[REF] => RHQ
[COLOR] => RED
[L1] => 4
)
[1] => Array
(
[NUMCIE] => 001
[REF] => RXL
[COLOR] => BLUE
[L1] => 6
)
[2] => Array
(
[NUMCIE] => 001
[REF] => RXL
[COLOR] => RED
[L1] => 4
)
[3] => Array
(
[NUMCIE] => 002
[REF] => RXL
[COLOR] => YELLOW
[L1] => 8
)
)
----
Server IP: 195.221.21.36
Probable Submitter: 86.64.19.206
----
Manual Page -- http://www.php.net/manual/en/function.array-multisort.php
Edit -- https://master.php.net/note/edit/104659
Del: integrated -- https://master.php.net/note/delete/104659/integrated
Del: useless -- https://master.php.net/note/delete/104659/useless
Del: bad code -- https://master.php.net/note/delete/104659/bad+code
Del: spam -- https://master.php.net/note/delete/104659/spam
Del: non-english -- https://master.php.net/note/delete/104659/non-english
Del: in docs -- https://master.php.net/note/delete/104659/in+docs
Del: other reasons-- https://master.php.net/note/delete/104659
Reject -- https://master.php.net/note/reject/104659
Search -- https://master.php.net/manage/user-notes.php