我有一个多维数组,如:
Array
(
[name] => Array
(
[0] => South Africa
[1] => Australia
[2] => Egypt
)
[img] => Array
(
[0] => sa-flag.jpg
[2] => au-flag.jpg
[1] => eg-flag.jpg
)
)
,我想按字母顺序排序,这样它的输出将完全像:
Array
(
[name] => Array
(
[0] => Australia
[1] => Egypt
[2] => South Africa
)
[img] => Array
(
[0] => au-flag.jpg
[2] => eg-flag.jpg
[1] => sa-flag.jpg
)
)
我无法在两个键上使用排序来同步国家名称和国家标志。
请参见下面的解决方案
$kd = array(
'name' => array(
'0' => 'South Africa',
'1' => 'Australia',
'2' => 'Egypt',
),
'img' => array
(
'0' => 'sa-flag.jpg',
'2' => 'au-flag.jpg',
'1' => 'eg-flag.jpg',
),
);
array_multisort($kd['name'], SORT_ASC, SORT_STRING,$kd['img'], SORT_ASC, SORT_STRING);
echo '<pre>';
print_r($kd);
查找核心概念
http://www.php.net/manual/en/function.array-multisort.php的例子- 4840
试试这个
$arr = array_multisort($array);