关于合并二维数组的有关问题
程序员文章站
2022-05-29 16:57:36
...
关于合并二维数组的问题
有一个数组:
Array
(
[0] => Array
(
[a] => Array
(
[id] => 4
)
)
[1] => Array
(
[a] => Array
(
[id] => 5
)
)
[2] => Array
(
[b] => Array
(
[id] => 4
)
)
[3] => Array
(
[b] => Array
(
[id] => 7
)
)
)
请问如何合并成
Array(
[0]=>4
[1]=>5
[2]=>4
[3]=>7
)
value都是二维数组id
------解决思路----------------------
------解决思路----------------------
有一个数组:
Array
(
[0] => Array
(
[a] => Array
(
[id] => 4
)
)
[1] => Array
(
[a] => Array
(
[id] => 5
)
)
[2] => Array
(
[b] => Array
(
[id] => 4
)
)
[3] => Array
(
[b] => Array
(
[id] => 7
)
)
)
请问如何合并成
Array(
[0]=>4
[1]=>5
[2]=>4
[3]=>7
)
value都是二维数组id
------解决思路----------------------
$arr = Array
(
'0' => Array
(
'a' => Array
(
'id' => 4
)
),
'1' => Array
(
'a' => Array
(
'id' => 5
)
),
'2' => Array
(
'b' => Array
(
'id' => 4
)
),
'3' => Array
(
'b' => Array
(
'id' => 7
)
)
);
$new_arr = array();
foreach($arr as $vl){
foreach($vl as $v) $new_arr[] = $v['id'];
}
print_r($new_arr);
------解决思路----------------------
$a = array (
0 =>
array (
'a' =>
array (
'id' => '4',
),
),
1 =>
array (相关文章
相关视频
上一篇: 利用PHP的OOP特性实现数据保护(1)_PHP教程
下一篇: php框架防止注入代码