src/Utilities/Arrays.php
public static function arrayDiffRecursive(array $array1, array $array2, $valuesOnly = false)
    {
        $effect = [];

        /*
         * Values should be compared only and both arrays are one-dimensional?
         * Let's find difference by using simple function
         */
        if ($valuesOnly && 1 === self::getDimensionsCount($array1) && 1 === self::getDimensionsCount($array2)) {
            return array_diff($array1, $array2);
        }

        foreach ($array1 as $key => $value) {
            $array2HasKey = array_key_exists($key, $array2);

            // Values should be compared only?
            if ($valuesOnly) {
                $difference = null;

                if (is_array($value)) {
                    if ($array2HasKey && is_array($array2[$key])) {
                        $difference = self::arrayDiffRecursive($value, $array2[$key], $valuesOnly);
                    }
                } elseif (!$array2HasKey || ($array2HasKey && $value !== $array2[$key])) {
                    /*
                     * We are here, because:
                     * a) 2nd array hasn't key from 1st array
                     * OR
                     * b) key exists in both, 1st and 2nd array, but values are different
                     */
                    $difference = $value;
                }

                if (null !== $difference) {
                    $effect[] = $difference;
                }

                // The key exists in 2nd array?
            } elseif ($array2HasKey) {
                // The value it's an array (it's a nested array)?
                if (is_array($value)) {
                    $diff = [];

                    if (is_array($array2[$key])) {
                        // Let's verify the nested array
                        $diff = self::arrayDiffRecursive($value, $array2[$key], $valuesOnly);
                    }

                    if (empty($diff)) {
                        continue;
                    }

                    $effect[$key] = $diff;
                } elseif ($value !== $array2[$key]) {
                    // Value is different than in 2nd array?
                    // OKay, I've got difference
                    $effect[$key] = $value;
                }
            } else {
                // OKay, I've got difference
                $effect[$key] = $value;
            }
        }

        return $effect;
    }
public static function arrayDiffRecursive(array $array1, array $array2, $valuesOnly = false)
    {
        $effect = [];

        /*
         * Values should be compared only and both arrays are one-dimensional?
         * Let's find difference by using simple function
         */
        if ($valuesOnly && 1 === self::getDimensionsCount($array1) && 1 === self::getDimensionsCount($array2)) {
            return array_diff($array1, $array2);
        }

        foreach ($array1 as $key => $value) {
            $array2HasKey = array_key_exists($key, $array2);

            // Values should be compared only?
            if ($valuesOnly) {
                $difference = null;

                if (is_array($value)) {
                    if ($array2HasKey && is_array($array2[$key])) {
                        $difference = self::arrayDiffRecursive($value, $array2[$key], $valuesOnly);
                    }
                } elseif (!$array2HasKey || ($array2HasKey && $value !== $array2[$key])) {
                    /*
                     * We are here, because:
                     * a) 2nd array hasn't key from 1st array
                     * OR
                     * b) key exists in both, 1st and 2nd array, but values are different
                     */
                    $difference = $value;
                }

                if (null !== $difference) {
                    $effect[] = $difference;
                }

                // The key exists in 2nd array?
            } elseif ($array2HasKey) {
                // The value it's an array (it's a nested array)?
                if (is_array($value)) {
                    $diff = [];

                    if (is_array($array2[$key])) {
                        // Let's verify the nested array
                        $diff = self::arrayDiffRecursive($value, $array2[$key], $valuesOnly);
                    }

                    if (empty($diff)) {
                        continue;
                    }

                    $effect[$key] = $diff;
                } elseif ($value !== $array2[$key]) {
                    // Value is different than in 2nd array?
                    // OKay, I've got difference
                    $effect[$key] = $value;
                }
            } else {
                // OKay, I've got difference
                $effect[$key] = $value;
            }
        }

        return $effect;
    }
public static function arrayDiffRecursive ( array $ array1 , array $ array2 , $ valuesOnly = false ) { $ effect = [ ] ; /*
         * Values should be compared only and both arrays are one-dimensional?
         * Let's find difference by using simple function
         */ if ( $ valuesOnly && 1 === self :: getDimensionsCount ( $ array1 ) && 1 === self :: getDimensionsCount ( $ array2 ) ) { return array_diff ( $ array1 , $ array2 ) ; } foreach ( $ array1 as $ key => $ value ) { $ array2HasKey = array_key_exists ( $ key , $ array2 ) ; // Values should be compared only? if ( $ valuesOnly ) { $ difference = null ; if ( is_array ( $ value ) ) { if ( $ array2HasKey && is_array ( $ array2 [ $ key ] ) ) { $ difference = self :: arrayDiffRecursive ( $ value , $ array2 [ $ key ] , $ valuesOnly ) ; } } elseif ( ! $ array2HasKey || ( $ array2HasKey && $ value !== $ array2 [ $ key ] ) ) { /*
                     * We are here, because:
                     * a) 2nd array hasn't key from 1st array
                     * OR
                     * b) key exists in both, 1st and 2nd array, but values are different
                     */ $ difference = $ value ; } if ( null !== $ difference ) { $ effect [ ] = $ difference ; } // The key exists in 2nd array? } elseif ( $ array2HasKey ) { // The value it's an array (it's a nested array)? if ( is_array ( $ value ) ) { $ diff = [ ] ; if ( is_array ( $ array2 [ $ key ] ) ) { // Let's verify the nested array $ diff = self :: arrayDiffRecursive ( $ value , $ array2 [ $ key ] , $ valuesOnly ) ; } if ( empty ( $ diff ) ) { continue ; } $ effect [ $ key ] = $ diff ; } elseif ( $ value !== $ array2 [ $ key ] ) { // Value is different than in 2nd array? // OKay, I've got difference $ effect [ $ key ] = $ value ; } } else { // OKay, I've got difference $ effect [ $ key ] = $ value ; } } return $ effect ; }
Returns an array containing all the entries from 1st array that are not present in 2nd array.
An item from 1st array is the same as in 2nd array if both, keys and values, are the same.

Example of difference:
$array1 = [
1 => 'Lorem',
2 => 'ipsum,
];

$array2 = [
1 => 'Lorem',
5 => 'ipsum,        // <-- The same values, but different key. Here we got 5, in 1st array - 2.
];

@param array $array1     The 1st array to verify
@param array $array2     The 2nd array to verify
@param bool  $valuesOnly (optional) If is set to true, compares values only. Otherwise - keys and values
(default behaviour).
@return array
Returns an array containing all the entries from 1st array that are not present in 2nd array . An item from 1st array is the same as in 2nd array if both keys and values are the same .