Home > Article > Backend Development > array_combine() function in PHP
array_combine() function creates an array by using one array as keys and another array as values. It returns the combined array. If the number of elements in each array does not match, the function returns FALSE.
array_combine(keys, values);
keys − Array of keys.
values − Array of values.
array_combine() function returns the combined array. Returns FALSE if the number of elements in each array does not match.
The following is an example of merging two arrays.
Demonstration
<?php $sports= array('football', 'cricket'); $players= array('david', 'steve'); $res = array_combine($sports, $players); print_r($res); ?>
The following is the output -
Array ( [football] => david [cricket] => steve )
The above is the detailed content of array_combine() function in PHP. For more information, please follow other related articles on the PHP Chinese website!