PHP.nl

array_combine

array_combine

Creates an array by using one array for keys and another for its values

array **array_combine** array $keys array $values

Creates an by using the values from the array as keys and the values from the array as the corresponding values. array``keys``values

keys Array of keys to be used. Illegal values for key will be converted to . string

values of values to be used Array

Returns the combined . array

As of PHP 8.0.0, a is thrown if the number of elements in and does not match. Prior to PHP 8.0.0, a was emitted instead. ValueError``keys``values``E_WARNING

Voorbeeld: A simple example

<?php
$a = array('green', 'red', 'yellow');
$b = array('avocado', 'apple', 'banana');
$c = array_combine($a, $b);

print_r($c);
?>
Array
(
    [green] => avocado
    [red] => apple
    [yellow] => banana
)

array_merge``array_walk``array_values``array_map