Questions tagged [array-combine]

A PHP function that creates an array by using the values from the keys array as keys and the values from the values array as the corresponding values.

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 array by using the values from the keys array as keys and the values from the values array as the corresponding values.

Returns the combined array, FALSE if the number of elements for each array isn't equal.

Example:

$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
)
47 questions
-2
votes
2 answers

Why array combine is not working

I have two strings and i want to concatenate string like john+smith to jsomhinth. i did this but array_combine not showing the result set. array_combine is not working here What is the use of array_combine?
-3
votes
1 answer

Combine multiple array with one array key

I have a situation in PHP where I need to combine multiple array values and bind with the first array key, Let say I have following array, [services] => Array ( [0] => 1 [1] => 2 [2] => 1 ) …
1 2 3
4