PHP array_combine()Function
Complete PHP Array Reference Manual
Examples
Create a new array by merging two arrays, where elements of one array are the keys and elements of the other array are the values:
<?php
$fname=array("Peter","Ben","Joe");
$age=array("35","37","43");
$c=array_combine($fname,$age);
print_r($c);
?>
$fname=array("Peter","Ben","Joe");
$age=array("35","37","43");
$c=array_combine($fname,$age);
print_r($c);
?>
Run Example »
Definition and Usage
The array_combine() function creates a new array by merging two arrays, where elements of one array are keys and elements of the other array are values.
Note:The number of elements in the keys array and the values array must be the same!
Syntax
array_combine(keys,values);
| Parameter | Description |
|---|---|
| keys | Required. Specifies the keys of the array. |
| values | Required. Specifies the values of the array. |
Technical Details
| Return value: | Returns the merged array. If the two arrays have different numbers of elements, it returns FALSE. |
|---|---|
| PHP Version: | 5+ |
| Changelog: | Before PHP 5.4, if the array was empty, an E_WARNING level error would be issued and FALSE returned. |
Complete PHP Array Reference Manual Other Extensions