2 回答
TA贡献1851条经验 获得超5个赞
您的排序似乎比最初出现的要复杂一些。您想先按值排序,然后按键排序。你可以用array_multisort这个。
<?php
$a = [ 'Arvind' => 'Basu', 'Rampal' => 'Singh' ];
$b = [ 'Anjali' => 'Basu', 'Roopashri' => 'Singh' ];
// You could also use `array_merge`. You should read about the differences.
// https://stackoverflow.com/a/7059731/296555
$c = $b + $a;
array_multisort(array_values($c), SORT_ASC, array_keys($c), SORT_ASC, $c);
var_dump($c);
array(4) {
["Anjali"]=> string(4) "Basu"
["Arvind"]=> string(4) "Basu"
["Rampal"]=> string(5) "Singh"
["Roopashri"]=> string(5) "Singh"
}
TA贡献1827条经验 获得超9个赞
这应该做。这是一个示例。
$a = [ 'Arvind' => 'Basu', 'Rampal' => 'Singh' ];
$b = [ 'Anjali' => 'Basu', 'Roopashri' => 'Singh' ];
$c = array_merge($a, $b);
ksort($c);
echo print_r($c);
- 2 回答
- 0 关注
- 91 浏览
添加回答
举报