我有两个数组:
$ ARRAY1:
Array
(
[0] => Array
(
[category] => Baggage
)
[1] => Array
(
[category] => Camp Dues
)
[2] => Array
(
[category] => Extended Care
)
[3] => Array
(
[category] => Transportation
)
[4] => Array
(
[category] => Trips
)
[5] => Array
(
[category] => Tuition
)
)
$数组2:
Array
(
[0] => Baggage
[1] => Cancellation fee
[2] => Extended Care
[3] => Transportation
[4] => Trips
[5] => Tuition
)
我要做的是将两个数组组合起来,看起来像数组2查找并删除重复的类别并按字母顺序排列数组。有没有什么方法可以与array_merge一起使用来实现这个目的?
答案 0 :(得分:1)
Php 5+到array_column
array_unique(array_merge(array_column($array1, "category"),$array2), SORT_REGULAR);
答案 1 :(得分:0)
这应该有效:
$array2 = array();
foreach($value in $array1){
$array2[] = $value["category"];
}