There are many array functions, you can master them one by one slowly. Now let’s make an introduction to the array_combine function. Its function is to combine two arrays, one by array key name and the other by array value, into a new array.
Detailed explanation of the array_combine() function in php
Create a new array by merging two arrays, where one array element is the key name and the other array element For key values:
<?php $fname=array("Peter","Ben","Joe"); $age=array("35","37","43"); $c=array_combine($fname,$age); print_r($c); ?>
Definition and usage
array_combine() function creates a new array by merging two arrays, where one array element is the key name and the other array element is key value.
Note: The number of elements in the key name array and the key value array must be the same!
Syntax
array_combine(keys,values);
Parameter Description
keys Required. Specifies the key name of the array.
values Required. Specifies the key value of the array.
Technical details Return value:
Returns 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.
The above is the detailed content of Detailed explanation of array_combine() function in php. For more information, please follow other related articles on the PHP Chinese website!