我有一个大的多维数组,我基本上想要删除第一级数组并构建一个没有数字键的数组:
我当前的数组:
Array
(
[0] => Array
(
[block_header14] => Array
(
[type] => block_header
[caption] => Silver
[collapsable] => 1
[collapsed] =>
)
[section14] => Array
(
[type] => checkbox_set
[name] => purchasable_memberships14
[caption] => Available Memberships
[values] => Array
(
[14] => Silver
[15] => Gold
)
[value] =>
)
)
[1] => Array
(
[block_header15] => Array
(
[type] => block_header
[caption] => Gold
[collapsable] => 1
[collapsed] =>
)
[section15] => Array
(
[type] => checkbox_set
[name] => purchasable_memberships15
[caption] => Available Memberships
[values] => Array
(
[14] => Silver
[15] => Gold
)
[value] =>
)
)
)
这就是我想要的结果:
Array
(
[block_header14] => Array
(
[type] => block_header
[caption] => Silver
[collapsable] => 1
[collapsed] =>
)
[section14] => Array
(
[type] => checkbox_set
[name] => purchasable_memberships14
[caption] => Available Memberships
[values] => Array
(
[14] => Silver
[15] => Gold
)
[value] =>
)
[block_header15] => Array
(
[type] => block_header
[caption] => Gold
[collapsable] => 1
[collapsed] =>
)
[section15] => Array
(
[type] => checkbox_set
[name] => purchasable_memberships15
[caption] => Available Memberships
[values] => Array
(
[14] => Silver
[15] => Gold
)
[value] =>
)
)
编辑:我重写了最初的foreach并跳过了额外的步骤:抱歉模糊的问题
foreach ($aMemLevels as $id =>$name) {
$aForm['inputs']['block_header'.$id] = array(
'type' => 'block_header',
'caption' => 'Available to ' . $name . ' Members',
'collapsable' => true,
'collapsed' => false
);
$aForm['inputs']['section'.$id] = array(
'type' => 'checkbox_set',
'name' => 'purchasable_memberships'.$id,
'values' => getMemberships(true),
'value' => $aValue,
);
}
答案 0 :(得分:2)
$new_array = array();
foreach($array as $value) {
$new_array = array_merge($new_array, $value);
}
print_r($new_array);
答案 1 :(得分:1)
我还没有测试过,但是这样的事情会有所帮助吗?
$new_array = array();
foreach ($multi_array as $inner_arr) {
$new_array = array_merge($new_array, $inner_array);
}
$ multi_array是你的初始多维数组...
如果有效,请告诉我。