Calculating the difference between 2 arrays
Regarding the way to achieve this task I couldn't find any better strategy than yours.

On the other hand your code may be made cleaner and more readable by:


first merely following best-practices (don't put several statements in the same line, 
using more significant names (such as $initial and $final instead of $array1 and $array2, $final_value and $initial_value rather than only $value)
avoiding to declare useless variables (like $array1diff, used only once)
using the more direct expressions when possible (e.g. $array2[key] is already available as $value, while -1 * $array1[$key] is merely -$array1[$key])
using the ternary operator where it can simplify the code (see also the note below)


It results in a reduced code:

function stock_diff($initial, $final) {
    foreach ($final as $key =&gt; $final_value) {
        $result[$key] = $final_value - @$initial[$key] ?: 0;
    }
    foreach(array_diff_key($initial, $final) as $key =&gt; $initial_value) {
        $result[$key] = -$initial_value;
    }
    return $result; 
}


NOTE: regarding the use of @ in the ternary operator, I know that many people automatically banish it as globally evil.
I don't agree with this too general point of view: sure it must be avoided in many situations where it might lead to some issues, but it's pretty legal when used carefully and with discernment.

In the case above, the only "error" it may hide is the one we know it may happen (undefined index), so it keeps sure.
And so it helps making the code more readable and reduced:
(isset($initial[$key]) ? $initial[$key] : 0)
is replaced by
@$initial[$key] ?: 0

The only con is about performance: using @ works slightly slower than isset(). So avoid it when you know that a piece of code will be executed a significantly huge number of times.