我有一个看起来像这样的数组:
array (
'id' => 1,
'channel_id' => 1,
'field_group' => 1,
'url_title' => 'the_very_first_entry',
'title' => 'The Very First Entry',
'fields' =>
array (
0 =>
array (
'label' => 'Enter Item Name:',
'type' => 'text',
'channel_data_id' => 1,
'value' => 'Item one',
'field_id' => 1
),
1 =>
array (
'label' => 'Enter Item Description',
'type' => 'textarea',
'channel_data_id' => 2,
'value' => 'Some long text blah blah',
'field_id' => 2
)
)
)
Run Code Online (Sandbox Code Playgroud)
我想把它分成2个数组,一个包含字段,另一个包含其他所有数组,即.
数组1:
array (
'id' => 1,
'channel_id' => 1,
'field_group' => 1,
'url_title' => 'the_very_first_entry',
'title' => 'The Very First Entry'
);
Run Code Online (Sandbox Code Playgroud)
数组2:
array (
0 =>
array (
'label' => 'Enter Item Name:',
'type' => 'text',
'channel_data_id' => 1,
'value' => 'Item one',
'field_id' => 1
),
1 =>
array (
'label' => 'Enter Item Description',
'type' => 'textarea',
'channel_data_id' => 2,
'value' => 'Some long text blah blah',
'field_id' => 2
)
)
Run Code Online (Sandbox Code Playgroud)
是否有更好的解决方案,使用foreach循环遍历原始数组?
是否有更好的解决方案,使用foreach循环遍历原始数组
你知道分裂键所以没有真正的用途foreach
:
$src = array(...); // your source array
$fields_array = $src['fields'];
unset($src['fields']);
Run Code Online (Sandbox Code Playgroud)