Пример из
документации:
$people = array(
array("name"=>"Bob","age"=>8,"colour"=>"red"),
array("name"=>"Greg","age"=>12,"colour"=>"blue"),
array("name"=>"Andy","age"=>5,"colour"=>"purple"));
var_dump($people);
$sortArray = array();
foreach($people as $person){
foreach($person as $key=>$value){
if(!isset($sortArray[$key])){
$sortArray[$key] = array();
}
$sortArray[$key][] = $value;
}
}
$orderby = "name"; //change this to whatever key you want from the array
array_multisort($sortArray[$orderby],SORT_DESC,$people);
var_dump($people);
Output from first var_dump:
[0]=>
array(3) {
["name"]=>
string(3) "Bob"
["age"]=>
int(8)
["colour"]=>
string(3) "red"
}
[1]=>
array(3) {
["name"]=>
string(4) "Greg"
["age"]=>
int(12)
["colour"]=>
string(4) "blue"
}
[2]=>
array(3) {
["name"]=>
string(4) "Andy"
["age"]=>
int(5)
["colour"]=>
string(6) "purple"
}
}
Output from 2nd var_dump:
array(3) {
[0]=>
array(3) {
["name"]=>
string(4) "Greg"
["age"]=>
int(12)
["colour"]=>
string(4) "blue"
}
[1]=>
array(3) {
["name"]=>
string(3) "Bob"
["age"]=>
int(8)
["colour"]=>
string(3) "red"
}
[2]=>
array(3) {
["name"]=>
string(4) "Andy"
["age"]=>
int(5)
["colour"]=>
string(6) "purple"
}