массивы

Объединение многомерных массивов _array_merge_recursive

25.12.2013 php ,

function _array_merge_recursive($dest, $new) {
			if (!is_array($dest) &&  is_array($new)) return $new;
			if ( is_array($dest) && !is_array($new)) return $dest;
			if (!is_array($dest) && !is_array($new)) return array();
			foreach ($new as $k => $v) {
				if (is_array($v) && isset($dest[$k]) && !is_numeric($k)) {
					$dest[$k] = _array_merge_recursive($dest[$k], $v);
				} else if (!is_numeric($k)) {
					$dest[$k] = $new[$k];
				} else {
					$dest[] = $new[$k];
				}
			}
			return $dest;
		}

Первый массив

Array
(
    [s1] => Array
        (
            [0] => 1
        )

    [BASKER_QUANTITY] => Array
        (
            [0] => 1
        )

    [ORDER] => Array
        (
            [632] => Array
                (
                    [0] => 1
                )

        )

)

Второй массив

Array
(
    [s1] => Array
        (
            [0] => 1
        )

    [BASKER_QUANTITY] => Array
        (
            [0] => 1
        )

    [ORDER] => Array
        (
            [1249] => Array
                (
                    [0] => 1
                )

        )

)

Результат

Array
(
    [s1] => Array
        (
            [0] => 1
            [1] => 1
        )

    [BASKER_QUANTITY] => Array
        (
            [0] => 1
            [1] => 1
        )

    [ORDER] => Array
        (
            [1249] => Array
                (
                    [0] => 1
                )

            [1250] => Array
                (
                    [0] => 1
                )

        )

)

Объединение одномерных массивов array_merge_recursive

15.08.2012 php No comments ,

        $ar1 = array('qw'=>12,1=>85,2=>78);
	$ar2 = array('qw'=>'aaa',1=>"ssss",2=>"dddd");
	$ar = 	array_merge_recursive($ar1, $ar2) ;
Array
(
    [qw] => Array
        (
            [0] => 12
            [1] => aaa
        )

    [0] => 85
    [1] => 78
    [2] => ssss
    [3] => dddd
)