The array_combine() function creates an array by using one array for keys and another for its values. It returns the combined array. The function returns FALSE if the number of elements of each array does not match.
Syntax
array_combine(keys, values);
Parameters
keys − Array of keys.
values − Array of values.
Return
The array_combine() function returns the combined array. It returns FALSE if the number of elements of each array does not match.
The following is an example combining two arrays.
Example
<?php $sports= array('football', 'cricket'); $players= array('david', 'steve'); $res = array_combine($sports, $players); print_r($res); ?>
Output
The following is the output −
Array ( [football] => david [cricket] => steve )