[Solved] Sort a multi dimensional array in php using keys


Here is how I accomplished this. There is probably a better way, but we need to create a new array in memory with the alpha-characters as the actual keys (basically we are removing the parent arrays we don’t need). Then we use ksort to actually sort the array.

<?php 
$test = array(
    array("a" => array("status" =>1, "blah" => 2)),
    array("f" => array("status" =>1, "blah" => 2)),
    array("c" => array("status" =>1, "blah" => 2)),
    array("b" => array("status" =>1, "blah" => 2)),
    array("z" => array("status" =>1, "blah" => 2))
);
foreach($test as $key=>$val){
    foreach($val as $key2=>$val2){
        $newTest[$key2] = $val2;
    }
}
echo '<pre>';
var_dump($test);
ksort($newTest);
var_dump($newTest);
echo '</pre>';
?>

1

solved Sort a multi dimensional array in php using keys