PHP array_combine() Function

PHP array_combine Function


PHP array_combine() Function
The array_combine() function in PHP is used to create an array by combining two arrays i.e., one array for keys and another array for its values.
 
Syntax of array_combine()
array_combine ( array $keys , array $values )
 
Parameter:
 
keys(required)- This parameter represents an array which acts as keys for the new array.
values(required)- This parameter signifies an array which acts as values for the new array.
Return
This function returns the combined array if the number of elements for each array is equal else it returns FALSE.
Errors/Exception
This function throws an E_WARNING if the number of elements in keys and values does not match.
Example :

Output :

Array
(
    [Pink] => Strawberry
    [red] => Apple
    [yellow] => Mango
)