PHP array_combine() Function

0

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.

Parameter Description
keys Required. Array of keys
values Required. 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 
)