I have these arrays in the beggining:
Array
(
[products] => Array
(
[0] => 5
[1] => 4
[2] => 6
[3] => 8
[4] => 4
)
[qtys] => Array
(
[0] => 20
[1] => 22
[2] => 100
[3] => 0
[4] => 0
)
)
I when to combine these arrays in order to have this :
Array
(
[0] => Array
(
[product_id] => 5
[qty] => 20
)
[1] => Array
(
[product_id] => 20
[qty] => 22
) ...
But with this foreach :
$products = $post['products'];
$qtys = $post['qtys'];
$array = [];
foreach($products as $product){
foreach($qtys as $quantity){
if(!in_array($product, $array)){
$array[] = array(
'product_id' => $product,
'qty' => $quantity
);
}
}
}
echo "<pre>".print_r($array, true)."</pre>";
I have this result :
Array
(
[0] => Array
(
[product_id] => 5
[qty] => 20
)
[1] => Array
(
[product_id] => 5
[qty] => 22
)
I tried many this, for example with break, continue. I even tried array_combine, the result wasn't what I expected. I thought about using array_unique, but is not working with multidimensional arrays (that's what I understood).