I have this array in PHP. But I want to extract each item of the array and put it in the outside array like this:
[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
)
)
)
But I want it to be like this:
[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
)
)
How Can I do that??
I have tried this:
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'];
But it does not work, can you help me please.
Thanks
[0] -> [1]and[1] -> [0], and you're modifying the parent array while iterating it, which isn't generally a good idea.