PHP - 如何在数组内合并数组
2022-08-30 08:50:19
如何在php中合并n个数组。我的意思是我怎么能做这样的工作:
或array_merge(from : $result[0], to : $result[count($result)-1])
array_merge_recursive(from: $result[0], to : $result[count($result) -1])
其中是一个数组,其中包含多个数组,如下所示:$result
$result = Array(
0 => array(),//associative array
1 => array(),//associative array
2 => array(),//associative array
3 => array()//associative array
)
我的结果是:
$result = Array(
0 => Array(
"name" => "Name",
"events" => 1,
"types" => 2
),
1 => Array(
"name" => "Name",
"events" => 1,
"types" => 3
),
2 => Array(
"name" => "Name",
"events" => 1,
"types" => 4
),
3 => Array(
"name" => "Name",
"events" => 2,
"types" => 2
),
4 => Array(
"name" => "Name",
"events" => 3,
"types" => 2
)
)
我需要的是
$result = Array(
"name" => "name",
"events" => array(1,2,3),
"types" => array(2,3,4)
)