<?php
function subtrai_array( $arr1, $arr2 ) {
foreach ( $arr2 as $chave => $valor ) {
$arr1[$chave] = $arr1[$chave] - $valor;
} else {
$arr1[$chave] = -$valor;
}
}
return $arr1;
}
'bife' => 3,
'batata' => 2,
'arroz' => 1,
'zóião' => 3
);
'bife' => 2,
'batata' => 2,
'couve' => 1
);
print_r( subtrai_array
( $a1, $a2 ) ); ?>
PD9waHAKCglmdW5jdGlvbiBzdWJ0cmFpX2FycmF5KCAkYXJyMSwgJGFycjIgKSB7CgkJZm9yZWFjaCAoICRhcnIyIGFzICRjaGF2ZSA9PiAkdmFsb3IgKSB7CgkJICAgIGlmKCBhcnJheV9rZXlfZXhpc3RzKCAkY2hhdmUsICRhcnIxICkgKSB7CgkJICAgICAgICAkYXJyMVskY2hhdmVdID0gJGFycjFbJGNoYXZlXSAtICR2YWxvcjsKCQkJfSBlbHNlIHsKCQkJCSRhcnIxWyRjaGF2ZV0gPSAtJHZhbG9yOwoJCQl9CgkJfQoJCXJldHVybiAkYXJyMTsKCX0KCgkkYTEgPSBBcnJheSAoCgkgICAgJ2JpZmUnID0+IDMsCgkgICAgJ2JhdGF0YScgPT4gMiwKCSAgICAnYXJyb3onID0+IDEsCgkJJ3rDs2nDo28nID0+IDMKCSk7CgkkYTIgPSBBcnJheSAoCgkgICAgJ2JpZmUnID0+IDIsCgkgICAgJ2JhdGF0YScgPT4gMiwKCSAgICAnY291dmUnID0+IDEKCSk7CglwcmludF9yKCBzdWJ0cmFpX2FycmF5KCAkYTEsICRhMiApICk7Cj8+