Ok l'ho trovato anche io, inoltre c'è un esempio con una funzione già pronta.
codice:
<?php
function arrayColumnSort()
{
$n = func_num_args();
$ar = func_get_arg($n-1);
if(!is_array($ar))
return false;
for($i = 0; $i < $n-1; $i++)
$col[$i] = func_get_arg($i);
foreach($ar as $key => $val)
foreach($col as $kkey => $vval)
if(is_string($vval))
${"subar$kkey"}[$key] = $val[$vval];
$arv = array();
foreach($col as $key => $val)
$arv[] = (is_string($val) ? ${"subar$key"} : $val);
$arv[] = $ar;
call_user_func_array("array_multisort", $arv);
return $ar;
}
$test["pete"]['points']=1;
$test["pete"]['name']='Peter';
$test["mike"]['points']=5;
$test["mike"]['name']='Mike';
$test["zoo"]['points']=2;
$test["zoo"]['name']='John Zoo';
$test["ab"]['points']=2;
$test["ab"]['name']='John Ab';
$test1 = $test;
asort($test1);
$test2 = arrayColumnSort("points", SORT_DESC, SORT_NUMERIC, "name", SORT_ASC, SORT_STRING, $test);
print_r($test1); // asort
print_r($test2); // arrayColumnSort
?>
Però nn ho capito capito se devo defnire ogni volta tutte le colonne quando faccio questo
$test2 = arrayColumnSort("points", SORT_DESC, SORT_NUMERIC, "name", SORT_ASC, SORT_STRING, $test);
o basta anche una?
grazie