I´m trying to sort the last dimension of the following array
$inventory = array(
"author" => array(
"1" => "Evans, Dave",
"2" => "Burnett, Bill",
),
"title" => array(
"1" => "Designing your life",
),
"subject" => array(
"1" => "Vocational guidance",
"2" => "Decision making",
"3" => "Self-realization",
)
);
The desired output would be something like this:
author Burnett, Bill
author Evans, Dave
title Designing your life
subject Decision making
subject Self-realization
subject Vocational guidance
There are a bunch of sorting examples that doesn’t work. Any ideas? Please don’t answer without testing.
2
Answers
Thanks RJK (and Rob Eyre) for this usefull answer. I have come to this solution, using asort within a for loop.
But I think the array_walk solution is more professional. Thanks.
You can do either of the following:
var_dump
returns:var_dump
returns:Note that both of these solutions will change the type of your indexes from
string
toint
.