我有一个数组,看起来像这样:PHP分裂阵列的关键
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
)
)
)
我想这个分裂成2个数组,一个包含字段,另含一切,即。
阵列1:
array (
'id' => 1,
'channel_id' => 1,
'field_group' => 1,
'url_title' => 'the_very_first_entry',
'title' => 'The Very First Entry'
);
阵列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
)
)
是否有更好的解决方案,通过原阵列foreach循环迭代?
谢谢。这正是我目前所掌握的。我认为可能会有一个“更好的”解决方案,以原生php函数的形式输出原始数组的2个所需部分,而无需取消设置。 – Inigo
还有一些其他的方法可以使用,但似乎试图做到的所有其他答案基本上都被破坏了,或者是假设字段是数组的最后一个元素,需要更多步骤才能实现目标或不能正确处理某些情况。保持简单的事情简单:) –