この方法で試すことができます:
<?php
function record_sort($records, $field, $reverse=false)
{
$hash = array();
foreach($records as $record)
{
$hash[$record[$field]] = $record;
}
($reverse)? krsort($hash) : ksort($hash);
$records = array();
foreach($hash as $record)
{
$records []= $record;
}
return $records;
}
// Example below
$airports = array
(
array( "code" => "LHR", "name" => "Heathrow" ),
array( "code" => "LGW", "name" => "Gatwick" ),
);
printf("Before: <pre>%s</pre>", print_r($airports, true));
$airports = record_sort($airports, "name");
printf("After: <pre>%s</pre>", print_r($airports, true));
?>
Example Outputs:
Before: Array
(
[0] => Array ( [code] => LHR, [name] => Heathrow )
[1] => Array ( [code] => LGW, [name] => Gatwick )
)
After: Array
(
[0] => Array ( [code] => LGW, [name] => Gatwick )
[1] => Array ( [code] => LHR, [name] => Heathrow )
)
http://php.net/manual/en/function.asort.phpから