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
-1
votes
3 answers

foreach array_combine two array by php

There are two arrays that One is the correct answers and the other is the user's answer. My Php: $i=1; $correct = array('a','d','c','a','b','c'); $user = array('a','c','c','a','c','c'); foreach (array_combine($correct, $user) as $co => $ur) { …
behroz
  • 84
  • 7
-1
votes
1 answer

How to combine multiple arrays of duplicate first element (Combine only second element) in PHP?

I've an array of arrays in which I've 2 values in each array first one is personID and second one is Skill, there are multiple skills of same persons I need all same skills to add in an array with single person id. I can't figure how to do it. Raw…
-1
votes
2 answers

loop through an array and compare object values to combine respective arrays

Here is my array , I need to loop through this array and check if objects with same docId exists and if they do, I have to combine jArray of these objects FinalArray = [ { "jArray": [ { "Cd": "A" …
aki
  • 175
  • 1
  • 3
  • 14
-1
votes
1 answer

Why can't I add a key and value when PHP array_key_exists is FALSE?

I am simply trying to add a set of keys and values to an array if and only if they are not already in the array. I need to add d1 thru d20 when they are not already in the array, Here is my code. print_r($demos_keys) Array ( [0] => d01 [1]…
David Weisser
  • 117
  • 1
  • 10
-1
votes
2 answers

Array_combine error: puts out the wrong values and gives only the unique values php

hi all i have 2 arrays [0] => CD Alaves [1] => Granada CF [2] => Getafe [3] => CD Leganes [4] => Barcelona [5] => Getafe [6] => Atletico Madrid [7] => Getafe [8] => Sevilla [9] => Athletic Bilbao [10] => CD Leganes and their corresponding…
miikegunn
  • 1
  • 1
-1
votes
3 answers

Merge/combine (not sure which i need?) the php array if keys [any][0] are the same number

Using the following code I am able to convert an uploaded CSV file into a php array..
Glen Keybit
  • 296
  • 2
  • 15
-1
votes
2 answers

Single error iterated but almost fully successful array_combine: Warning: array_combine() expects parameter 2 to be array, boolean

Here is the full csv file to which this problem pertains. I don't understand how the error Warning: array_combine() expects parameter 2 to be array, boolean given in C:\xampp\htdocs\kalugi\auscomp\test.php on line 18 applies in this case,…
user136649
  • 59
  • 1
  • 7
-1
votes
1 answer

Insert in database two different arrays from a dynamic input to the same table

I have a form with dynamic inputs, in this case, I take a car owner with multiple cars, so for the same person/client I need to save several cars with the brand name and year model:
-1
votes
1 answer

Single arrays to associative array in php codeigniter ( Combine Arrays )

i have two arrays :- $a1=array(1,1,2,3,1);
$a2=array("m","m","s","xl","s"); i want this as output what should i do :- Array ( [0] => Array ( [0] => 1 [1] => m [2] => 2 //this is count of m …
-1
votes
1 answer

array_combine removed duplicate array

Array_combine remove duplicate array This code give output : Array ( [red] => yellow ) But I want output like this:…
-1
votes
1 answer

How can I merge between two multidimensional array respected their keys

Let's say I have following arrays: Array ( [2001] => Array ( [event_detail] => Array ( [1] => Array ( [event_name] => Advocacy CPD 2019 …
-2
votes
1 answer

Combine two arrays with multiple values and same keys

I have two arrays with keys and values and i want to combine them: Array 1 [0]=>string "Width" [1]=>string "Height" [2]=>string "Length" [3]=>string "Width" [4]=>string "Height" [5]=>string "Length" Array 2 [0]=>string "42 cm" [1]=>string "2…
w2God
  • 19
  • 4
-2
votes
2 answers

Combine Two Multidimensional Arrays on matching key values in PHP

Problem i have two multidimensional arrays that look like this, 1st Array array( [0] => Array ( [course_id] => 10 [topic] => Booda-hood, advice and an important pit. [lesson_id] => 10 ) [1] => Array ( …
Atif Raja
  • 17
  • 4
-2
votes
2 answers

Combine value array in php

i have problem to combine values based on id. I have data like this : Array( [0] => Array( [id] => 1, [id_name] => a [id_vales] => 5 ) [1] => Array( [id] => 1 [id_name] => a [id_vales]…
axhxs
  • 15
  • 2
-2
votes
2 answers

php multidimensional array get prices in specific category

[0] => Array ( [id] => 004002718 [price] => 5.00 [category] => x ) [1] => Array ( [id] => 030285882 [price] => 8.99 [category] => y ) [2] => Array ( [id] => 040685111 …