Reputation: 12923
Like the title sais I have no idea where to start and using asort() and sort() are not helping in the way I thought it would. Essentially I have an array as such:
$array = array(
'array_c' => array(
'array_b' => (
array('object' => 'e some Object'),
array('object' => 'b some Object'),
),
'array_a' => (
array('object' => 'awesome Object'),
),
),
'array_a' => array(
'array_e' => (
array('object' => 'e some Object'),
),
'array_a' => (
array('object' => 'b awesome Object'),
);
);
);
So I was looking at asort as I want to keep the associations the same, The function I have started writing is:
function sort_me(some_array){
$new_array = asort(some_array);
return $new_array;
}
this function then takes in $array['array_c'] so that you get back an alphabetically sorted array that looks like:
'array_c' => array(
'array_a' => (
array('object' => 'awesome Object'),
),
'array_b' => (
array('object' => 'b some Object'),
array('object' => 'e some Object'),
),
),
can some one tell me why my function is not working? Am I misunderstanding the power of asort?
Upvotes: 0
Views: 93
Reputation: 481
ksort is the way to go, but ksort does not return a newly sorted array:
it returns a bool -> true if the array could be sorted, otherwise false...
this code snipped should do what you need:
ksort($array);
foreach($array as $key=>$value){
ksort(value);
$array[$key]=$value;
}
print_r($array);
Upvotes: 1