The array_combine() function creates an associative array by using the elements from "keys" array and "values" array.
Both arrays must have equal number of elements!
array_combine has the following syntax.
array_combine(keys,values);
Parameter | Is Required | Description |
---|---|---|
keys | Required. | Array of keys |
values | Required. | Array of values |
array_combine() function returns the combined array. It returns FALSE if number of elements does not match.
Create an array by using the elements from one "keys" array and one "values" array:
<?php
$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.