In PHP, the array_combine() function is used to merge two arrays into an associative array. One array’s elements serve as the keys, while the other array’s elements become the values, resulting in a combined array. If the two arrays have mismatched lengths, the function will return FALSE.
array_combine
The array_combine() function returns the merged associative array. If the two arrays do not have the same number of elements, it will return FALSE.
Here is an example that merges two arrays:
<?php
$sports = array('football', 'cricket');
$players = array('david', 'steve');
<p>$res = array_combine($sports, $players);<br>
print_r($res);<br>
?>
The output from running the above code is as follows:
Array
(
[football] => david
[cricket] => steve
)
From this example, we can clearly see that the array_combine() function successfully combines the two arrays into an associative array.