I have a multidimensional array, and both the parent array and the child arrays are associative.
While there are various ways out there to sort multidimensional arrays with numeric top level and associative child levels by child value (like here or here), I'm lost doing so in my case where the top level is associative, too.
Here is my code:
$dbstructure = array (
'documents' => array (
'prettyname' => array ('en' => 'Documents', 'pl' => 'Dokumenty', 'de' => 'Dokumente'),
'columns' => array ('file', 'name', 'descr', 'tags' ),
),
'photos' => array (
'prettyname' => array ('en' => 'Photos', 'pl' => 'Zdjęcia', 'de' => 'Fotos'),
'columns' => array ('name', 'file', 'descr', 'publish', 'tags', 'file_date' ),
),
'users' => array (
'prettyname' => array ('en' => 'Users', 'pl' => 'Użytkownicy', 'de' => 'Benutzer'),
'columns' => array ('name', 'password', 'email', 'role', 'status', 'lang' ),
)
);
The array is part of a config file that describes a db structure, and I want to sort the first level by ...['prettyname'][$lang]
, $lang
being either 'en'
, 'pl'
or 'de'
. In other words, users shall get the table names in the right alphabetical order in their language.
Brit gets this order: 'documents'
- 'photos'
- 'users'
Pole gets: 'documents'
- 'users'
- 'photos'
(Dokumenty - Użytkownicy - Zdjęcia)
German gets: 'users'
- 'documents'
- 'photos'
(Benutzer - Dokumente - Fotos)
Any help is greatly appreciated. Thanks!