У меня этот массив в PHP. Но я хочу, чтобы извлечь каждый элемент массива и поместить его в окружающем массиве, как это:Извлечь массив из внутреннего массива в PHP
[PordersProduct] => Array
(
[0] => Array
(
[1] => Array
(
[product_id] => 300001300
[Product] => Array
(
[name] => RELLENO CARNE P/ EMPANADA X KG
)
[requested] => 2.500
[formula_quantity] => 0
[cep_quantity] => 35.723
[wr_semi_finished_quantity] => 0
[in_execution_quantity] => 7488.131
[wr_total_semi_finished_quantity] => 7523.854
[to_produced_orders_quantity] => 0
)
)
[1] => Array
(
[0] => Array
(
[product_id] => 300002841
[Product] => Array
(
[name] => DISCO PARA EMPANDAS DE 85 GRS POR UNIDAD
)
[requested] => 50
[formula_quantity] => 0
[cep_quantity] => 0
[wr_semi_finished_quantity] => 0
[in_execution_quantity] => 7925
[wr_total_semi_finished_quantity] => 7925
[to_produced_orders_quantity] => 0
)
)
)
Но я хочу, чтобы это было так:
[PordersProduct] => Array
(
[0] => Array
(
[product_id] => 300001300
[Product] => Array
(
[name] => RELLENO CARNE P/ EMPANADA X KG
)
[requested] => 2.500
[formula_quantity] => 0
[cep_quantity] => 35.723
[wr_semi_finished_quantity] => 0
[in_execution_quantity] => 7488.131
[wr_total_semi_finished_quantity] => 7523.854
[to_produced_orders_quantity] => 0
)
[1] => Array
(
[product_id] => 300002841
[Product] => Array
(
[name] => DISCO PARA EMPANDAS DE 85 GRS POR UNIDAD
)
[requested] => 50
[formula_quantity] => 0
[cep_quantity] => 0
[wr_semi_finished_quantity] => 0
[in_execution_quantity] => 7925
[wr_total_semi_finished_quantity] => 7925
[to_produced_orders_quantity] => 0
)
)
Как я могу это сделать ??
Я попытался это:
grouped_data_porders2 = array(); // other array
foreach ($grouped_data_porders['PordersProduct'] as $key => $item) {
$grouped_data_porders2['PordersProduct'][] = $item[$key];
}
$grouped_data_porders['PordersProduct'] = $grouped_data_porders2['PordersProduct'];
Но это не работает, вы можете помочь мне, пожалуйста.
Благодаря
Ваши ключи не совпадают, например. '[0] -> [1]' и '[1] -> [0]', и вы изменяете родительский массив при его итерации, что обычно не является хорошей идеей. –
grouped_data_porders2 это еще один массив, оригинал - grouped_data_porders без 2 – juanpscotto
Возможный дубликат [Объединить массивы PHP в простой массив?] (Http://stackoverflow.com/questions/30308665/merge-php-arrays-into-simple- массив) – CodeGodie