Skip to content

Instantly share code, notes, and snippets.

@Gronghon
Created February 8, 2016 21:37
Show Gist options
  • Save Gronghon/739a68a35e1bd8b4c473 to your computer and use it in GitHub Desktop.
Save Gronghon/739a68a35e1bd8b4c473 to your computer and use it in GitHub Desktop.
php sort array
<?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