php array_merge with same numeric keys code example

Example 1: php merge array with same value

function custom_array_merge(&$array1, &$array2) {
    $result = Array();
    foreach ($array1 as $key_1 => &$value_1) {
        // if($value['name'])
        foreach ($array2 as $key_1 => $value_2) {
            if($value_1['name'] ==  $value_2['name']) {
                $result[] = array_merge($value_1,$value_2);
            }
        }

    }
    return $result;
}

Example 2: array merge with same key in php

Input : $a1=array("a"=>"raj", "b"=>"striver");
        $a2=array("z"=>"geeks", "b"=>"articles");
Output : 
Array
(
    [a] => raj
    [b] => Array
        (
            [0] => striver
            [1] => articles
        )

    [z] => geeks
)

Tags:

Php Example