Created
February 8, 2016 21:37
-
-
Save Gronghon/739a68a35e1bd8b4c473 to your computer and use it in GitHub Desktop.
php sort array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$tableau = array( | |
"id_cat4" => array( | |
"zom_cat1", | |
"éom_cat1" => array( | |
"nom_elem3" => "description_elem1", | |
"nom_elem2" => "description_elem2", | |
"nom_elem1" => "description_elem2" | |
), | |
"éom_cat3" => array( | |
"nom_elem3" => "description_elem1", | |
"nom_elem2" => "description_elem2", | |
"nom_elem1" => "description_elem2" | |
), | |
"2om_cat1" => array( | |
"nom_elem3" => "description_elem1", | |
"nom_elem2" => "description_elem2", | |
"nom_elem1" => "description_elem2" | |
) | |
), | |
"id_cat2" => array( | |
"éom_cat1" => array( | |
"nom_elem3" => "description_elem1", | |
"nom_elem2" => "description_elem2", | |
"nom_elem1" => "description_elem2" | |
), | |
"éom_cat3" => array( | |
"nom_elem3" => "description_elem1", | |
"nom_elem2" => "description_elem2", | |
"nom_elem1" => "description_elem2" | |
), | |
"2om_cat1" => array( | |
"nom_elem3" => "description_elem1", | |
"nom_elem2" => "description_elem2", | |
"nom_elem1" => "description_elem2" | |
) | |
), | |
); | |
function recur_ksort(&$array) { | |
foreach ($array as &$value) { | |
if (is_array($value)) recur_ksort($value); | |
} | |
return ksort($array, SORT_LOCALE_STRING); | |
} | |
recur_ksort($tableau); | |
var_dump($tableau); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment