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
0
votes
1 answer

Plotting multiple data sets as one average and adding error bars- matplotlib

I need to analyze some data taken in my lab but it goes beyond my limited programming skills. I have multiple sets of similar data and I need to take the average of all of these and plot that with error bars. The idea is to plot the area of an…
0
votes
2 answers

php: combine multiple arrays value into one array preserving keys

I have multiple arrays structured like these: $array1 = ["aaa" => 1, "bbb" => 1]; $array2 = ["aaa" => 12, "bbb" => 12]; $array3 = ["bbb" => 15, "ccc" => 15]; meaning: every array has the same value for each key (eg: array1 has value "1" for every…
Lou Nik
  • 115
  • 4
0
votes
2 answers

PHP array_combine if not null

I want to combine data only if value is exist. example: // array 1 array:4 [▼ 0 => "qwfd" 1 => "qw2e3" 2 => null 3 => null ] // array 2 array:4 [▼ 0 => "qwef" 1 => "w2" 2 => null 3 => null ] I need to ignore 2=> and 3=> in both…
mafortis
  • 6,750
  • 23
  • 130
  • 288
0
votes
1 answer

Combine integers in list into one integer

this is what I wish for... INPUT [1,2,3,4,5] OUTPUT 12345 I've tried this but it didn't work... l1 = [1,2,3,4,5,6] print([int(n1) for n1 in str(l1).split() if n1.isdigit()])
0
votes
1 answer

PHP combine_array produces false when element count is the same

Apologies if this question is close to others. I have tried every solution to accomplish something simple with nothing but failure. :-( I want the keys from array one to be assigned as keys to array two. $demos_keys = array_keys($demos); //$c =…
David Weisser
  • 117
  • 1
  • 10
0
votes
1 answer

PHP Warning: array_combine() and array_merge() generating warning

The below code is generating several of the below error and it's pointing to PHP Warning: array_merge(): Expected parameter 1 to be an array, null given in /home/mike/snmpCode.php on line 20 PHP Warning: array_combine(): Both parameters should…
Mike T
  • 47
  • 3
0
votes
1 answer

PHP Array combine values with same string key

I have the following issue that seems common but can't figure out which array function might work for the following format: (Already tried array_merge , array_merge_recursive , array_combine, array_splice but didn't work as expected.) Array ( …
0
votes
2 answers

How to fill a empty value in KEY=> VALUE for array_combine in php

I wish to make Key and Value combining with 2 arrays, but both arrays are not equal. $array1 = array("1","2","3","4","5"); $array2 = array("apple","banana","","dog",""); $key_value = array_combine($array1,$array2); The output is: array_combine():…
Balaji P
  • 21
  • 7
0
votes
1 answer

Combine One array to several array

I have following content: $staticArray = ['group_1', 'group_2']; foreach ($staticArray as $name){ $names[] = $name; } $staticArray2 = ['one', 'two']; $i = 0; foreach ($staticArray2 as $name){ $item['group']['name'] = $names; …
0
votes
0 answers

PHP - Array_combine first row missing

I have a problem with Array_combine function. I want to combine prices to set as products keys. First I get everything as string from html form. and use explode function make it array. this process for both. Here it is a short of code; $urunler…
0
votes
0 answers

Looping into CSV file, combine multiple data arrays

I'm working on file import feature from an Excel file. During the import, I'm using PhpSpreadSheet library to convert this file to CSV format. Next, my function extractData() will loop csv file, detect specific headers, combine data corresponding…
Maestro
  • 865
  • 1
  • 7
  • 24
0
votes
1 answer

Merge two arrays by index value by different value in the array

I have two arrays and I want to merge the values of the two arrays into a single array, but both arrays have different values. Example: var arr1 = [ { data1: 1 ,data2: "value1"}, { data1: 1 ,data2: "value2"}, {…
0
votes
1 answer

how to Pass 3 arguments in array_combine, is that possible?

i have three variables ($product_id, $size_id, $quantity) which get from "form" and insert into the pending_order table.So i used the array_combine function to combine three variables and than using for each loop to insert the multiple records. but…
0
votes
3 answers

Combining arrays but second array will add up values for array one

I want to add the second array values. For example $result will display the output as $result[1] = 4, // it will add the all values for the…
0
votes
2 answers

Alter array rows to be associative and append an additional associative element

I've created a method that allows me to assign keys to rows of values, and appends extra keys and values. It adds all the new keys to a keys array, then adds all new values to the values array, and then combines all the keys and values. How can I…