Code:
$array = array('even' => array(array('key' => 'test','key2' => 'Wn'), array('key' => 'test3', 'key2' => 'Bx')),
'not_even' => array(array('key' => 'test2','key2' => 'Xn'), array('key' => 'test4', 'key2' => 'Gy')),
);
echo '<pre>';
print_r($array);
echo '</pre>';
Output:
Array
(
[even] => Array
(
[0] => Array
(
[key] => test
[key2] => Wn
)
[1] => Array
(
[key] => test3
[key2] => Bx
)
)
[not_even] => Array
(
[0] => Array
(
[key] => test2
[key2] => Xn
)
[1] => Array
(
[key] => test4
[key2] => Gy
)
)
)
I want sort it and result should be:
Array
(
[0] => Array
(
[key] => test
[key2] => Wn
)
[1] => Array
(
[key] => test2
[key2] => Xn
)
[2] => Array
(
[key] => test3
[key2] => Bx
)
[3] => Array
(
[key] => test4
[key2] => Gy
)
)
So how sort it? Keys in arrays should be: test test2 test3 test4. How use foreach or something else for this? What is the best solution. Important is "key", "key2" is not matter.
foreach()is a simple solution. The PHP functionsarray_map()andarray_reduce()could also help. What have you tried?