Sorting Multidimensional Arrays
<?php
$data = array(
array('country'=>'Spain', 'language'=>'Spanish', 'visitors'=>1289),
array('country'=>'France', 'language'=>'French', 'visitors'=>984),
array('country'=>'Argentina', 'language'=>'Spanish', 'visitors'=>812)
);
printf("<pre>%s</pre>\n", var_export($data, TRUE));
$cols = array();
foreach($data as $row) {
foreach($row as $key => $value) {
if( !isset($cols[$key]) )
$cols[$key] = array();
$cols[$key][] = $value;
}
}
$data = $cols;
array_multisort($data['language'], $data['country'], $data['visitors']);
printf("<pre>%s</pre>\n", var_export($data, TRUE));
?>
Related examples in the same category