The array_combine Function
The array_combine
function performs
merging of two arrays into one associative array.
The first parameter of the function accepts an array
of future keys, and the second - an array of future
values.
Syntax
array_combine(array $keys, array $values): array
Example
Let's merge two arrays into one associative array. In this case, the corresponding elements from the first array will become keys for the elements from the second array:
<?php
$keys = ['a' , 'b', 'c', 'd', 'e'];
$elems = [1, 2, 3, 4, 5];
$res = array_combine($keys, $elems);
var_dump($res);
?>
The code execution result:
['a'=>1, 'b'=>2, 'c'=>3, 'd'=>4, 'e'=>5]
See Also
-
the
array_merge
function,
which merges several arrays into one -
the
array_keys
function,
which extracts keys from an array -
the
array_values
function,
which extracts values from an array