public static function mergeDeepArray(array $arrays, $preserve_integer_keys = false)
    {
        $result = [];

        foreach ($arrays as $array) {
            foreach ($array as $key => $value) {
                if (is_integer($key) && !$preserve_integer_keys) {
                    // Renumber integer keys as array_merge_recursive() does unless
                    // $preserve_integer_keys is set to true. Note that PHP automatically
                    // converts array keys that are integer strings (e.g., '1') to integers.
                    $result[] = $value;
                } elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {
                    // Recurse when both values are arrays.
                    $result[$key] = self::mergeDeepArray(array($result[$key], $value), $preserve_integer_keys);
                } else {
                    // Otherwise, use the latter value, overriding any previous value.
                    $result[$key] = $value;
                }
            }
        }

        return $result;
    }