src/Type/StdArray.fix.php
function withMergeRecursive($b, $reserve = false)
    {
        if ($b instanceof StdArray)
            $b = $b->value;
        else
            $b = (array) $b;

        $a = $this->value;

        foreach ($b as $key => $value)
        {
            if (! array_key_exists($key, $a)) {
                // key not exists so simply add it to array
                $a[$key] = $value;
                continue;
            }


            if ( is_int($key) ) {
                // [ 'value' ] if value not exists append to array!
                if (! in_array($value, $a) )
                    $a[] = $value;

            } elseif (is_array($value) && is_array($a[$key]))  {
                // a= [k=>[]] , b=[k=>['value']]
                $m = new StdArray($a[$key]);
                $a[$key] = $m->withMergeRecursive($value, $reserve)->value;

            } else {
                if ($reserve) {
                    // save old value and push them into new array list
                    $cv = $a[$key];
                    $a[$key] = array();
                    $pa = &$a[$key];
                    array_push($pa, $cv);
                    array_push($pa, $value);
                } else {
                    $a[$key] = $value;
                }
            }
        }

        return new StdArray($a);
    }
function withMergeRecursive($b, $reserve = false)
    {
        if ($b instanceof StdArray)
            $b = $b->value;
        else
            $b = (array) $b;

        $a = $this->value;

        foreach ($b as $key => $value)
        {
            if (! array_key_exists($key, $a)) {
                // key not exists so simply add it to array
                $a[$key] = $value;
                continue;
            }


            if ( is_int($key) ) {
                // [ 'value' ] if value not exists append to array!
                if (! in_array($value, $a) )
                    $a[] = $value;

            } elseif (is_array($value) && is_array($a[$key]))  {
                // a= [k=>[]] , b=[k=>['value']]
                $m = new StdArray($a[$key]);
                $a[$key] = $m->withMergeRecursive($value, $reserve)->value;

            } else {
                if ($reserve) {
                    // save old value and push them into new array list
                    $cv = $a[$key];
                    $a[$key] = array();
                    $pa = &$a[$key];
                    array_push($pa, $cv);
                    array_push($pa, $value);
                } else {
                    $a[$key] = $value;
                }
            }
        }

        return new StdArray($a);
    }
function withMergeRecursive ( $ b , $ reserve = false ) { if ( $ b instanceof StdArray ) $ b = $ b -> value ; else $ b = ( array ) $ b ; $ a = $ this -> value ; foreach ( $ b as $ key => $ value ) { if ( ! array_key_exists ( $ key , $ a ) ) { // key not exists so simply add it to array $ a [ $ key ] = $ value ; continue ; } if ( is_int ( $ key ) ) { // [ 'value' ] if value not exists append to array! if ( ! in_array ( $ value , $ a ) ) $ a [ ] = $ value ; } elseif ( is_array ( $ value ) && is_array ( $ a [ $ key ] ) ) { // a= [k=>[]] , b=[k=>['value']] $ m = new StdArray ( $ a [ $ key ] ) ; $ a [ $ key ] = $ m -> withMergeRecursive ( $ value , $ reserve ) -> value ; } else { if ( $ reserve ) { // save old value and push them into new array list $ cv = $ a [ $ key ] ; $ a [ $ key ] = array ( ) ; $ pa = & $ a [ $ key ] ; array_push ( $ pa , $ cv ) ; array_push ( $ pa , $ value ) ; } else { $ a [ $ key ] = $ value ; } } } return new StdArray ( $ a ) ; }
Merge two arrays together, reserve previous values

@param  array|StdArray $b
@return StdArray
Merge two arrays together reserve previous values