PHP – array_combine function

This function takes two existing arrays and combines them into one array. Note that the first array must contain the key values that you want, while the second array must contain the values.


array_combine(name of the first array(keys),
        name of the second array(values))

Programming Samples and Usage:

$test = array ("a","b","c");
$test2 = array ("Superman", "Batman", "Sandman");

The above code takes the values in the array $test (representing the keys) and combines them with the values in $test2 (representing the values).

The result is:

array ([a] => Superman [b] => Batman  => Sandman)

Leave a Reply

Your email address will not be published. Required fields are marked *