I have an array like this:
array (size=3)
4 =>
array (size=3)
'id' => int 4
'parentId' => int 3
'name' => string 'z' (length=4)
5 =>
array (size=3)
'id' => int 4
'parentId' => int 3
'name' => string 'a' (length=4)
9 =>
array (size=3)
'id' => int 4
'parentId' => int 3
'name' => string 'd' (length=4)
And i have to sort this array ascending by name! The goal is, to make the array to the following structure:
array (size=3)
5 =>
array (size=3)
'id' => int 4
'parentId' => int 3
'name' => string 'a' (length=4)
9 =>
array (size=3)
'id' => int 4
'parentId' => int 3
'name' => string 'd' (length=4)
4 =>
array (size=3)
'id' => int 4
'parentId' => int 3
'name' => string 'z' (length=4)
Do you guys have any smart solutions? I've tried to save the keys and the name belongs to the key in a new array, and iterate the ksort'ed array once again, and set the new position:
// Placeholder
$categoryContainer = array();
// Iterate all categories
foreach(self::$categories as $key => $category) {
$categoryContainer[$category['name']] = $key;
}
// Resort by key (category name!)
ksort($categoryContainer);