将多维数组转换为单个数组我有一个无缘无故的多维数组。/* This is how my array is currently */Array([0] => Array
(
[0] => Array
(
[plan] => basic )
[1] => Array
(
[plan] => small )
[2] => Array
(
[plan] => novice )
[3] => Array
(
[plan] => professional )
[4] => Array
(
[plan] => master )
[5] => Array
(
[plan] => promo )
[6] => Array
(
[plan] => newplan )
)
)我想把这个数组转换成这个表单/*Now, I want to simply it down to this*/Array ([0] => basic[1] => small[2] => novice[3] => professional[4] => master[5]
=> promo[6] => newplan)知道怎么做吗?
3 回答
四季花海
TA贡献1811条经验 获得超5个赞
function array_flatten($array) { if (!is_array($array)) { return FALSE; } $result = array(); foreach ($array as $key => $value) { if (is_array($value)) { $result = array_merge($result, array_flatten($value)); } else { $result[$key] = $value; } } return $result; }
小怪兽爱吃肉
TA贡献1852条经验 获得超1个赞
$singleArray = array(); foreach ($multiDimensionalArray as $key => $value){ $singleArray[$key] = $value['plan']; }
- 3 回答
- 0 关注
- 414 浏览
添加回答
举报
0/150
提交
取消