Based on the @Bacco example, I will propose another way using array_merge_recursive. Basically it will combine the 2 arrays and generate an array of 2 keys when there is combination, then a loop with subtraction.
The example considers 2 arrays (stock and sale), where items of sale exist expressly in stock - sells only that is in stock.
$result = array_merge_recursive($a1, $a2);
foreach ($result as $key => $value )
{
if( is_array( $value ) )
{
$array[ $key ] = ($value[0] - $value[1]);
}
else
{
$array[ $key ] = $value;
}
}
Example in ideone, output:
+------------+-----------+-----------+-----------+-----------+
| estoque | produto.1 | produto.2 | produto.3 | produto.4 |
| quantidade | 2 | 5 | 3 | 9 |
+------------+-----------+-----------+-----------+-----------+
| venda | produto.1 | | produto.3 | |
| quantidade | 1 | | 2 | |
+------------+-----------+-----------+-----------+-----------+
| resultado | produto.1 | produto.2 | produto.3 | produto.4 |
| quantidade | 1 | 5 | 1 | 9 |
+------------+-----------+-----------+-----------+-----------+
What do you mean? What do you intend to do?
– Papa Charlie
the additional of a product... it checks what the customer adds with the standard product
– Willian
The second array has only keys from the first array, or it can contain a key without reference?
– Papa Charlie