合并具有不同 levels/dimensions 的数组
Merging arrays with different levels/dimensions
我有两个数组:
$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
)
)
$array2:
Array
(
[0] => Baggage
[1] => Cancellation fee
[2] => Extended Care
[3] => Transportation
[4] => Trips
[5] => Tuition
)
我想做的是将两个数组组合起来,使其看起来像数组 2 查找并删除重复的类别并将数组按字母顺序排列。有什么方法可以与 array_merge 一起使用来完成这个吗?
这应该有效:
$array2 = array();
foreach($value in $array1){
$array2[] = $value["category"];
}
Php 5+ 至 array_column
array_unique(array_merge(array_column($array1, "category"),$array2), SORT_REGULAR);
我有两个数组:
$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
)
)
$array2:
Array
(
[0] => Baggage
[1] => Cancellation fee
[2] => Extended Care
[3] => Transportation
[4] => Trips
[5] => Tuition
)
我想做的是将两个数组组合起来,使其看起来像数组 2 查找并删除重复的类别并将数组按字母顺序排列。有什么方法可以与 array_merge 一起使用来完成这个吗?
这应该有效:
$array2 = array();
foreach($value in $array1){
$array2[] = $value["category"];
}
Php 5+ 至 array_column
array_unique(array_merge(array_column($array1, "category"),$array2), SORT_REGULAR);