PHP array_combine() function combines two array to create new associative array
Description
The array_combine() function creates an associative array by using the elements from "keys" array and "values" array.
Note
Both arrays must have equal number of elements!
Syntax
array_combine has the following syntax.
array_combine(keys,values);
Parameter
Parameter | Is Required | Description |
---|---|---|
keys | Required. | Array of keys |
values | Required. | Array of values |
Return
array_combine() function returns the combined array. It returns FALSE if number of elements does not match.
Example
Create an array by using the elements from one "keys" array and one "values" array:
<?php//w ww.j ava 2 s .c o m
$fname=array("Python","Java","HTML","java2s.com");
$age=array("5","7","3","9");
$c=array_combine($fname,$age);
print_r($c);
?>
The code above generates the following result.