array merge key value php code example

Example 1: merge two arrays one as key to another php

// two arrays one become keys and second becomes values
array_combine ( array $keys , array $values );

Example 2: php combine values of two arrays

$all_arrays = array_merge($array1, $array2, $array3, ...);

Example 3: 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