J'essaye de comprendre pourquoi mon code ne fonctionnera pas comme je m'attends. J'ai un tableau:PHP usort à l'intérieur pour chaque ordre alphabétiquement
$persons = array(
0 => array(
'person' => 'John',
'children' => array('Eve', 'Mark', 'Alto')
),
1 => array(
'person' => 'Susy',
'children' => array('Ruby', 'Adam', 'Tõnu')
)
);
boucle tableau et enfants trier par ordre alphabétique
foreach($persons as $person) {
usort($person['children'], function($a, $b) {
return strcmp($a, $b);
});
var_dump($person['children']); //shows children array items alphabetically ordered
}
Mais après chidrens foreach sont encore en ordre de départ
var_dump($persons); //shows that children names are not ordered alphabetically
Merci pour votre temps