Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

array_combine

Description

The array_combine of Array for PHP creates an array by using one array for keys and another for its values.

Syntax

array_combine(array $keys, array $values): array

Parameters

keys

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

values

Array of values to be used

Return

Returns the combined array.

Examples

1 · keys values

<?

$keys = array('green', 'red', 'yellow');
$values = array('avocado', 'apple', 'banana');

$return = array_combine($keys, $values);

print_r($return);

?>
Array
(
    [green] => avocado
    [red] => apple
    [yellow] => banana
)

2 · same key

<?

$keys = array('green', 'green', 'green');
$values = array('avocado', 'apple', 'banana');

$return = array_combine($keys, $values);

print_r($return);

?>
Array
(
    [green] => banana
)
HomeMenu