A multi-dimensional array can be sorted using following code snippet.
function subval_sort($arr, $subKey, $sort) {
foreach($arr as $k => $v) {
$b[$k] = strtolower($v[$subKey]);
}
$sort($b);
foreach($b as $key => $val) {
$c[] = $arr[$key];
}
return $c;
}
$testArr = array(
0 => array("name" => "test", age => 20),
1 => array("name" => "smith", age=>30)
);
Usage: subval_sort($testArr, "name", arsort);
No comments:
Post a Comment