There is an array:
Array ( [0] => Array ( [0] => Array ( [order_id] => 4 [entry_id] => 5 [count] => 1 [price] => 1 [weight] => 0 ) [1] => Array ( [order_id] => 4 [entry_id] => 2 [count] => 1 [price] => 94.4 [weight] => 0.5 ) [2] => Array ( [order_id] => 4 [entry_id] => 1 [count] => 1 [price] => 38 [weight] => 2 ) ) [1] => Array ( [0] => Array ( [order_id] => 3 [entry_id] => 4 [count] => 1 [price] => 0 [weight] => 0 ) [1] => Array ( [order_id] => 3 [entry_id] => 5 [count] => 1 [price] => 1 [weight] => 0 ) [2] => Array ( [order_id] => 3 [entry_id] => 2 [count] => 1 [price] => 94.4 [weight] => 0.5 ) [3] => Array ( [order_id] => 3 [entry_id] => 1 [count] => 1 [price] => 38 [weight] => 2 ) ) [2] => Array ( [0] => Array ( [order_id] => 2 [entry_id] => 2 [count] => 1 [price] => 94.4 [weight] => 0.5 ) [1] => Array ( [order_id] => 2 [entry_id] => 1 [count] => 1 [price] => 38 [weight] => 2 ) ) [3] => Array ( [0] => Array ( [order_id] => 1 [entry_id] => 2 [count] => 1 [price] => 94.4 [weight] => 0.5 ) ) ) And the script:
$template_orders_prepare = array(); for($j = 0; $j < count($orders_prepare_list); $j++) { for($h = 0; $h < count($orders_prepare_list[$j]); $h++) { $order_id = $orders_prepare_list[$j][$h]['order_id']; $entry_id = $orders_prepare_list[$j][$h]['entry_id']; $template_orders_prepare[$order_id] = $entry_id; } } print_r($template_orders_prepare); The problem is specifically in this line, because entry_id given last, although there are several:
$template_orders_prepare[$order_id] = $entry_id; And to give them a few, I did this:
$template_orders_prepare[$order_id] .= $entry_id; And it worked as it should ( print_r($template_orders_prepare); ).
It was:
Array ( [4] => 1 [3] => 1 [2] => 1 [1] => 2 ) It became:
( [4] => 521 [3] => 4521 [2] => 21 [1] => 2 ) But not everything is so simple. It would seem, it outputs everything as needed, but it is not clear where, the following errors come out:
Notice: Undefined offset: 4 in ... Notice: Undefined offset: 3 in ... Notice: Undefined offset: 2 in ... Notice: Undefined offset: 1 in ... Which point to this unfortunate line:
$template_orders_prepare[$order_id] .= $entry_id; What only I did not do, since 5 probably rewrote everything and to no avail. After tormenting for 2 hours, I still did not understand why this happens, but at the same time the array also contains what is needed ..
$template_orders_prepare[$order_id] .= $entry_id;says to concatenate with the contents of an element of an array that does not exist. - etki$template_orders_prepare[$order_id] = $entry_id;- etki