I am using a foreach
loop to sort an associative array alphabetically. I would like to know if there is a more proper and/or efficient way of doing it.
The array:
Array
(
[gr_c] => Array
(
[f] => 'value...'
[a] => 'value...'
[d] => 'value...'
[m] => 'value...'
[c] => 'value...'
[t] => 'value...'
)
[gr_a] => Array
(
[h] => 'value...'
[e] => 'value...'
[m] => 'value...'
[a] => 'value...'
[o] => 'value...'
[i] => 'value...'
[c] => 'value...'
[t] => 'value...'
[b] => 'value...'
)
[gr_b] => Array
(
[h] => 'value...'
[d] => 'value...'
)
)
became:
Array
(
[gr_c] => Array
(
[a] => 'value...'
[c] => 'value...'
[d] => 'value...'
[f] => 'value...'
[m] => 'value...'
[t] => 'value...'
)
[gr_a] => Array
(
[a] => 'value...'
[b] => 'value...'
[c] => 'value...'
[e] => 'value...'
[h] => 'value...'
[i] => 'value...'
[m] => 'value...'
[o] => 'value...'
[t] => 'value...'
)
[gr_b] => Array
(
[d] => 'value...'
[h] => 'value...'
)
)
used snippet:
foreach ($array_name as $key => $value) {
ksort($array_name[$key]);
}