merge two arrays one as key to another php code example

Example 1: php combine arrays

$output = array_merge($array1, $array2);

Example 2: 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 3: php combine values of two arrays

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

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