Create a new array by merging two arrays, one with keys and the other with keys:
<?php$fname=array("Peter","Ben","Joe");$age=array("35","37","43");$c=array_combine($fname,$age) ;print_r($c);?>The array_combine() function creates a new array by merging two arrays, where the elements of one array are keys and the elements of the other array are key values.
Note: The number of elements in the key array and the key value array must be the same!
array_combine( keys , values );
parameter | describe |
---|---|
keys | Required. Specifies the key name of the array. |
values | Required. Specifies the key value of the array. |
Return value: | Return the merged array. If the two arrays have different numbers of elements, return FALSE. |
---|---|
PHP version: | 5+ |
Update log: | Before PHP 5.4, if the array is empty, an E_WARNING level error will be reported and FALSE will be returned. |