PHP array_combine() Function

The array_combine() function is used to creates an array by using one array for keys and another for its values.

It returns the combined array, FALSE if the number of elements for each array isn’t equal or if the arrays are empty.

ParameterDescription
keysRequired. Array of keys
valuesRequired. Array of values

Syntax

 array_combine(keys,values); 

Example

$firstname = array("Prince","James","Samuel");
$nickname =array("Alex","Lachlan","Cooper");
$array =array_combine($firstname,$nickname);
print_r($array);

Output

Array ( 
        [Prince] => Alex 
        [James] => Lachlan  
        [Samuel] => Cooper 
) 

Leave a Reply

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