What is the purpose of the php array_combine function?
The array_combine function is used to merge two arrays into a new array, with the values of one array as the keys of the new array and the values of the other array as the values of the new array. The syntax of this function is as follows:
array_combine(array $keys, array $values): array
The $keys represent the key array of the new array, and the $values represent the value array of the new array. If the lengths of the two arrays are not equal, the function will return false. Example:
$keys = array('a', 'b', 'c');
$values = array(1, 2, 3);
$result = array_combine($keys, $values);
print_r($result);
The output is:
Array
(
[a] => 1
[b] => 2
[c] => 3
)