51 questions
1
vote
1
answer
57
views
PHP combine two associative arrays with different keys
I want to combine two associative arrays with different amount of keys and keep all the keys in the final array even if they are null or empty
I have tried array_merge but the keys that are not ...
1
vote
4
answers
114
views
Use flat array's values to generate an associative array whose keys and values are given a static prefix
Is there a shorthand for the following code:
$result = array_combine(
array_map(fn($elem) => "key_$elem", $array),
array_map(fn($elem) => "value_$elem", $array)
);
...
-1
votes
3
answers
40
views
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 (...
-1
votes
1
answer
59
views
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 ...
0
votes
2
answers
37
views
combine 2 array with same key into 1 array
I have 2 Array:
$arr1 = Array (
[2] => Array ( [0] => 41000 [1] => 31079 )
[3] => Array ( [0] => 42963 [1] => 41189 )
)
$arr2 = Array (
[2] => ...
-1
votes
2
answers
139
views
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&...
1
vote
1
answer
44
views
how to combine an array with the same keyon react?
i have an output like this:
[
{ GolonganName: '3B - Niaga Besar', data: [ 172000 ] },
{ GolonganName: '3A - Niaga Kecil', data: [ 76700 ] },
{ GolonganName: '2B - Rumah Tangga Menengah', data: [ ...
0
votes
1
answer
216
views
Use column values from one subarray as keys for anotheer subarray's values
I have an object as below,
{"metaData":[{"name":"a"},{"name":"b"}],"rows":[[1,2],[3,4],[5,6]]}
I would like to change it to
[["a"=...
0
votes
0
answers
40
views
I don't want to combine two obyes and have keys
I combined 2 objects as below, but I don't want the keys to be in the output I get.
$link1 = '{"Success":true,"Result":[{"eventId":650810,"sportId":"2"...
0
votes
1
answer
2k
views
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 ...
-2
votes
1
answer
158
views
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 "...
0
votes
2
answers
64
views
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" =&...
1
vote
2
answers
398
views
How do I combine two rows with a the same identity?
I'm trying to combine 2 rows with the same identity. I've been looking for a solution, but somehow can't find a working solution. I'm trying to make a tracker for my stocks, but I want it to combine ...
-2
votes
2
answers
173
views
Combine Two Multidimensional Arrays on matching key values in PHP [closed]
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 ...
0
votes
2
answers
421
views
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 => &...
1
vote
1
answer
1k
views
Combine integers in list into one integer [duplicate]
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()])
-1
votes
1
answer
104
views
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.
...
1
vote
1
answer
100
views
How do I add variable numbers of key value pairs using PHP array_combine and for-loop?
I have a db in which I store 20 demographics.
The demographics come from a csv and are stored in array. Each array key is a placeholder: d1, d2, up to d20. The incoming data may be [race, gender, ...
0
votes
1
answer
66
views
PHP combine_array produces false when element count is the same [duplicate]
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 ...
1
vote
3
answers
332
views
php: better way to split string into associative array
I have a string like this:
"ALARM_ID/I4=1010001 ALARM_STATE/U4=eventcode ALARM_TEXT/A=WMR_MAP_EXPORT LOTS/A[1]=[ STEFANO ] ALARM_STATE/U1=1 WAFER/U4=1 VI_KLARF_MAP/A=/test/klarf.map KLARF_STEPID/...
0
votes
1
answer
345
views
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 ...
1
vote
0
answers
60
views
Reading 2 TXT files and parsing the files
I am very much a numbie to python.
DISPLAY should read: surname, Firstname, Day1 ,Day2,Both Days,NoDays
I have 2 txt files. employee.txt has the above information.
confpack has 2 lines : 1. going 2. ...
-1
votes
2
answers
203
views
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
...
0
votes
1
answer
413
views
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, ...
-1
votes
3
answers
231
views
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..
<?PHP
function readCSV($csvFile){
$file_handle = fopen($csvFile, 'r');
fgetcsv($file_handle);
...
-3
votes
1
answer
327
views
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
vote
1
answer
71
views
make output from array with same keys from the database
I get the information from the database. For example, my database data is as follows:
I get the information from the database. For example, my database data is as follows:
----------------------------...
0
votes
2
answers
874
views
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($...
-1
votes
2
answers
464
views
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\...
1
vote
0
answers
722
views
PHP Warning: array_combine(): Both parameters should have an equal number of elements - CSV not parsing properly?
For the following CSV file (3MB):
ACDF_cut.csv
And for the following code:
<?php
$file = fopen("ACDF_cut.csv","r");
$file2 = fopen("ACDF_cut_rounded.csv","w");
/* Map Rows and Loop Through ...
0
votes
1
answer
62
views
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){
...
0
votes
0
answers
64
views
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 ...
-2
votes
2
answers
66
views
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] => ...
-1
votes
1
answer
121
views
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:
<form action="...
-1
votes
1
answer
416
views
Single arrays to associative array in php codeigniter ( Combine Arrays )
i have two arrays :-
$a1=array(1,1,2,3,1);<br>
$a2=array("m","m","s","xl","s");
i want this as output what should i do :-
Array
(
[0] => Array
(
[0] => 1
...
-1
votes
1
answer
84
views
array_combine removed duplicate array
Array_combine remove duplicate array
<?php
$a1=array("red","red");
$a2=array("blue","yellow");
print_r(array_combine($a1,$a2));
?>
This code give output : ...
-2
votes
2
answers
215
views
php multidimensional array get prices in specific category [duplicate]
[0] => Array
(
[id] => 004002718
[price] => 5.00
[category] => x
)
[1] => Array
(
[id] => 030285882
[price] => 8.99
[...
0
votes
0
answers
120
views
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, ...
0
votes
1
answer
179
views
Merge two arrays by index value by different value in the array [duplicate]
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"},
...
0
votes
1
answer
539
views
how to Pass 3 arguments in array_combine, is that possible? [duplicate]
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 ...
-1
votes
1
answer
40
views
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
(
...
2
votes
1
answer
174
views
array_combine results only one result [duplicate]
I am using the following code to get two arrays into one json result. But getting only the first index as result. Is there any error in the code or anybody can suggest an alternate method to get the ...
0
votes
3
answers
64
views
Combining arrays but second array will add up values for array one
<?php
$keys = array(1,1,2,1,1);
$values = array(1,1,1,1,1);
$result = array_combine ($keys, $values);
?>
I want to add the second array values.
For example $result will display the output as
$...
-2
votes
2
answers
540
views
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 ...
2
votes
9
answers
6k
views
Comma-separated string to associative array with lowercase keys
I have a string like this:
$string = 'Apple, Orange, Lemone';
I want to make this string to:
$array = array('apple'=>'Apple', 'orang'=>'Orange', 'lemone'=>'Lemone');
How to achieve this?
I ...
0
votes
4
answers
104
views
Use first row of a 2d array as the new keys of each subsequent row
I'm looking for a solution to create an array of associative arrays from an array of indexed array where the first row should be used as the keys for all subsequent rows.
What I have is a csv/xls file ...
1
vote
3
answers
1k
views
Replace indexed keys in each row of a 2d array with a static word followed by an incremented counter
To save on typing out the key name for every single array, I want to be able to build lists like.
$lists = [
['A', 'B', 'C', 'D', 'E'],
['A', 'B', 'C', 'D', 'E'],
['A', 'B', 'C', 'D', 'E'],...
0
votes
2
answers
55
views
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 ...
1
vote
7
answers
190
views
Array Combine in PHP
I am trying to combine keys and values in arrays. I have an product_id with different price.
Let say
Product id and price
id 101 and price is 100
id 105 and price is 200
id 101 and price is 300
...
1
vote
2
answers
611
views
array_combine() on each subarrays of two multidimensional arrays
In PHP, I have 2 multidimensional arrays. such as:
array 1:
[[1, 2, 3], [1, 2, 3]];
Array 2:
[[4, 5, 6], [7, 8, 9]];
I need to combine these two arrays.
I need the first array's subarray values to ...