Merge multiple arrays from into single array [closed] Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?php merge two arraysCreate ArrayList from arrayPHP: Delete an element from an arrayWhat's the simplest way to print a Java array?Sort array of objects by string property valueHow to merge two arrays in JavaScript and de-duplicate itemsReference — What does this symbol mean in PHP?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?Copy array by valueFor-each over an array in JavaScript?
Why are there no cargo aircraft with "flying wing" design?
Should I call the interviewer directly, if HR aren't responding?
Sorting numerically
Is there a service that would inform me whenever a new direct route is scheduled from a given airport?
What are 'alternative tunings' of a guitar and why would you use them? Doesn't it make it more difficult to play?
How to motivate offshore teams and trust them to deliver?
Doubts about chords
What is the longest distance a 13th-level monk can jump while attacking on the same turn?
How do I keep my slimes from escaping their pens?
Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?
What happens to sewage if there is no river near by?
Bonus calculation: Am I making a mountain out of a molehill?
If a contract sometimes uses the wrong name, is it still valid?
Can Pao de Queijo, and similar foods, be kosher for Passover?
How does a Death Domain cleric's Touch of Death feature work with Touch-range spells delivered by familiars?
What are the motives behind Cersei's orders given to Bronn?
How to bypass password on Windows XP account?
Center align columns in table ignoring minus signs?
Output the ŋarâþ crîþ alphabet song without using (m)any letters
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
Is a manifold-with-boundary with given interior and non-empty boundary essentially unique?
Why does Python start at index -1 when indexing a list from the end?
What's the purpose of writing one's academic bio in 3rd person?
List *all* the tuples!
Merge multiple arrays from into single array [closed]
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?php merge two arraysCreate ArrayList from arrayPHP: Delete an element from an arrayWhat's the simplest way to print a Java array?Sort array of objects by string property valueHow to merge two arrays in JavaScript and de-duplicate itemsReference — What does this symbol mean in PHP?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?Copy array by valueFor-each over an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
How to merge below array
Array
(
[0] => 14
)
Array
(
[0] => 18
)
and get output as
Array
(
[0] => 14
[1] => 18
)
I am using below code but not working for me
$result = call_user_func_array("array_merge", $input);
php arrays
closed as off-topic by RamRaider, Andreas, u_mulder, Nick, mickmackusa Mar 24 at 6:40
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – u_mulder, Nick, mickmackusa
|
show 15 more comments
How to merge below array
Array
(
[0] => 14
)
Array
(
[0] => 18
)
and get output as
Array
(
[0] => 14
[1] => 18
)
I am using below code but not working for me
$result = call_user_func_array("array_merge", $input);
php arrays
closed as off-topic by RamRaider, Andreas, u_mulder, Nick, mickmackusa Mar 24 at 6:40
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – u_mulder, Nick, mickmackusa
you can usearray_merge
– Ramesh Kumar
Mar 22 at 8:27
1
Code, not php version.
– u_mulder
Mar 22 at 8:37
1
3v4l.org/L6cEJ your error is somewhere else. Enable error reporting and check.
– u_mulder
Mar 22 at 8:41
1
@AmodKumar we don't need your scenario, we need exact code which is NOT working.
– u_mulder
Mar 22 at 8:45
2
I think the array posted is created in a loop and he tries to merge after the loop. That is why he has two seperate arrays in the outpiut
– Andreas
Mar 22 at 8:47
|
show 15 more comments
How to merge below array
Array
(
[0] => 14
)
Array
(
[0] => 18
)
and get output as
Array
(
[0] => 14
[1] => 18
)
I am using below code but not working for me
$result = call_user_func_array("array_merge", $input);
php arrays
How to merge below array
Array
(
[0] => 14
)
Array
(
[0] => 18
)
and get output as
Array
(
[0] => 14
[1] => 18
)
I am using below code but not working for me
$result = call_user_func_array("array_merge", $input);
php arrays
php arrays
edited Mar 22 at 8:25
Vadim Kotov
4,87863549
4,87863549
asked Mar 22 at 8:23
Amod KumarAmod Kumar
63
63
closed as off-topic by RamRaider, Andreas, u_mulder, Nick, mickmackusa Mar 24 at 6:40
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – u_mulder, Nick, mickmackusa
closed as off-topic by RamRaider, Andreas, u_mulder, Nick, mickmackusa Mar 24 at 6:40
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – u_mulder, Nick, mickmackusa
you can usearray_merge
– Ramesh Kumar
Mar 22 at 8:27
1
Code, not php version.
– u_mulder
Mar 22 at 8:37
1
3v4l.org/L6cEJ your error is somewhere else. Enable error reporting and check.
– u_mulder
Mar 22 at 8:41
1
@AmodKumar we don't need your scenario, we need exact code which is NOT working.
– u_mulder
Mar 22 at 8:45
2
I think the array posted is created in a loop and he tries to merge after the loop. That is why he has two seperate arrays in the outpiut
– Andreas
Mar 22 at 8:47
|
show 15 more comments
you can usearray_merge
– Ramesh Kumar
Mar 22 at 8:27
1
Code, not php version.
– u_mulder
Mar 22 at 8:37
1
3v4l.org/L6cEJ your error is somewhere else. Enable error reporting and check.
– u_mulder
Mar 22 at 8:41
1
@AmodKumar we don't need your scenario, we need exact code which is NOT working.
– u_mulder
Mar 22 at 8:45
2
I think the array posted is created in a loop and he tries to merge after the loop. That is why he has two seperate arrays in the outpiut
– Andreas
Mar 22 at 8:47
you can use
array_merge
– Ramesh Kumar
Mar 22 at 8:27
you can use
array_merge
– Ramesh Kumar
Mar 22 at 8:27
1
1
Code, not php version.
– u_mulder
Mar 22 at 8:37
Code, not php version.
– u_mulder
Mar 22 at 8:37
1
1
3v4l.org/L6cEJ your error is somewhere else. Enable error reporting and check.
– u_mulder
Mar 22 at 8:41
3v4l.org/L6cEJ your error is somewhere else. Enable error reporting and check.
– u_mulder
Mar 22 at 8:41
1
1
@AmodKumar we don't need your scenario, we need exact code which is NOT working.
– u_mulder
Mar 22 at 8:45
@AmodKumar we don't need your scenario, we need exact code which is NOT working.
– u_mulder
Mar 22 at 8:45
2
2
I think the array posted is created in a loop and he tries to merge after the loop. That is why he has two seperate arrays in the outpiut
– Andreas
Mar 22 at 8:47
I think the array posted is created in a loop and he tries to merge after the loop. That is why he has two seperate arrays in the outpiut
– Andreas
Mar 22 at 8:47
|
show 15 more comments
4 Answers
4
active
oldest
votes
Use array_merge
method: http://php.net/manual/en/function.array-merge.php
<?php
$array = array("1" );
$otherArray = array("2");
$result = array_merge($array, $otherArray);
print_r($result);
see live code: http://sandbox.onlinephpfunctions.com/code/7fb9da6de4fa9d0a8b220a06d2a59e9007655df1
This is not what op has. Op has one array, not two arrays
– Andreas
Mar 22 at 8:31
2
He has two arrays
– Snake Eyes
Mar 22 at 8:32
According to OP he has one multidimensional array.
– Andreas
Mar 22 at 8:35
You didn't read correctly. He want a result consist of two items in an array.
– Snake Eyes
Mar 22 at 8:58
add a comment |
Surely just array_merge
will suffice?
$a=[14];
$b=[18];
$c=[23];
$d=[44];
$e=[27];
$f=[31];
$g=[99];
$out=array_merge($a,$b,$c,$d,$e,$f,$g);
printf('<pre>%s</pre>',print_r($out,true));
This will output:
Array
(
[0] => 14
[1] => 18
[2] => 23
[3] => 44
[4] => 27
[5] => 31
[6] => 99
)
add a comment |
OP asks about merging arrays from one array. We don't know how many arrays there, so we need to use array_walk_recursive function. Pass $result from public scope by reference(!) in anonymous function and store in it all inner arrays values
$a = [[1], [2, 3]];
$result = [];
array_walk_recursive($a, function($value) use (&$result)
$result[] = $value;
);
var_dump($result);
add a comment |
Why call_user_func?
$a = array(14);
$b = array(18);
$merged = array_merge($a,$b);
I have array in single variable as $var Array ( [0] => 14 ) Array ( [0] => 18 )
– Amod Kumar
Mar 22 at 8:29
i have used above code as recommended by u but not working for me.
– Amod Kumar
Mar 22 at 8:29
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use array_merge
method: http://php.net/manual/en/function.array-merge.php
<?php
$array = array("1" );
$otherArray = array("2");
$result = array_merge($array, $otherArray);
print_r($result);
see live code: http://sandbox.onlinephpfunctions.com/code/7fb9da6de4fa9d0a8b220a06d2a59e9007655df1
This is not what op has. Op has one array, not two arrays
– Andreas
Mar 22 at 8:31
2
He has two arrays
– Snake Eyes
Mar 22 at 8:32
According to OP he has one multidimensional array.
– Andreas
Mar 22 at 8:35
You didn't read correctly. He want a result consist of two items in an array.
– Snake Eyes
Mar 22 at 8:58
add a comment |
Use array_merge
method: http://php.net/manual/en/function.array-merge.php
<?php
$array = array("1" );
$otherArray = array("2");
$result = array_merge($array, $otherArray);
print_r($result);
see live code: http://sandbox.onlinephpfunctions.com/code/7fb9da6de4fa9d0a8b220a06d2a59e9007655df1
This is not what op has. Op has one array, not two arrays
– Andreas
Mar 22 at 8:31
2
He has two arrays
– Snake Eyes
Mar 22 at 8:32
According to OP he has one multidimensional array.
– Andreas
Mar 22 at 8:35
You didn't read correctly. He want a result consist of two items in an array.
– Snake Eyes
Mar 22 at 8:58
add a comment |
Use array_merge
method: http://php.net/manual/en/function.array-merge.php
<?php
$array = array("1" );
$otherArray = array("2");
$result = array_merge($array, $otherArray);
print_r($result);
see live code: http://sandbox.onlinephpfunctions.com/code/7fb9da6de4fa9d0a8b220a06d2a59e9007655df1
Use array_merge
method: http://php.net/manual/en/function.array-merge.php
<?php
$array = array("1" );
$otherArray = array("2");
$result = array_merge($array, $otherArray);
print_r($result);
see live code: http://sandbox.onlinephpfunctions.com/code/7fb9da6de4fa9d0a8b220a06d2a59e9007655df1
edited Mar 22 at 8:28
Mikhail Vladimirov
11.4k12631
11.4k12631
answered Mar 22 at 8:26
Snake EyesSnake Eyes
8,4102685160
8,4102685160
This is not what op has. Op has one array, not two arrays
– Andreas
Mar 22 at 8:31
2
He has two arrays
– Snake Eyes
Mar 22 at 8:32
According to OP he has one multidimensional array.
– Andreas
Mar 22 at 8:35
You didn't read correctly. He want a result consist of two items in an array.
– Snake Eyes
Mar 22 at 8:58
add a comment |
This is not what op has. Op has one array, not two arrays
– Andreas
Mar 22 at 8:31
2
He has two arrays
– Snake Eyes
Mar 22 at 8:32
According to OP he has one multidimensional array.
– Andreas
Mar 22 at 8:35
You didn't read correctly. He want a result consist of two items in an array.
– Snake Eyes
Mar 22 at 8:58
This is not what op has. Op has one array, not two arrays
– Andreas
Mar 22 at 8:31
This is not what op has. Op has one array, not two arrays
– Andreas
Mar 22 at 8:31
2
2
He has two arrays
– Snake Eyes
Mar 22 at 8:32
He has two arrays
– Snake Eyes
Mar 22 at 8:32
According to OP he has one multidimensional array.
– Andreas
Mar 22 at 8:35
According to OP he has one multidimensional array.
– Andreas
Mar 22 at 8:35
You didn't read correctly. He want a result consist of two items in an array.
– Snake Eyes
Mar 22 at 8:58
You didn't read correctly. He want a result consist of two items in an array.
– Snake Eyes
Mar 22 at 8:58
add a comment |
Surely just array_merge
will suffice?
$a=[14];
$b=[18];
$c=[23];
$d=[44];
$e=[27];
$f=[31];
$g=[99];
$out=array_merge($a,$b,$c,$d,$e,$f,$g);
printf('<pre>%s</pre>',print_r($out,true));
This will output:
Array
(
[0] => 14
[1] => 18
[2] => 23
[3] => 44
[4] => 27
[5] => 31
[6] => 99
)
add a comment |
Surely just array_merge
will suffice?
$a=[14];
$b=[18];
$c=[23];
$d=[44];
$e=[27];
$f=[31];
$g=[99];
$out=array_merge($a,$b,$c,$d,$e,$f,$g);
printf('<pre>%s</pre>',print_r($out,true));
This will output:
Array
(
[0] => 14
[1] => 18
[2] => 23
[3] => 44
[4] => 27
[5] => 31
[6] => 99
)
add a comment |
Surely just array_merge
will suffice?
$a=[14];
$b=[18];
$c=[23];
$d=[44];
$e=[27];
$f=[31];
$g=[99];
$out=array_merge($a,$b,$c,$d,$e,$f,$g);
printf('<pre>%s</pre>',print_r($out,true));
This will output:
Array
(
[0] => 14
[1] => 18
[2] => 23
[3] => 44
[4] => 27
[5] => 31
[6] => 99
)
Surely just array_merge
will suffice?
$a=[14];
$b=[18];
$c=[23];
$d=[44];
$e=[27];
$f=[31];
$g=[99];
$out=array_merge($a,$b,$c,$d,$e,$f,$g);
printf('<pre>%s</pre>',print_r($out,true));
This will output:
Array
(
[0] => 14
[1] => 18
[2] => 23
[3] => 44
[4] => 27
[5] => 31
[6] => 99
)
answered Mar 22 at 8:27
RamRaiderRamRaider
18.7k31935
18.7k31935
add a comment |
add a comment |
OP asks about merging arrays from one array. We don't know how many arrays there, so we need to use array_walk_recursive function. Pass $result from public scope by reference(!) in anonymous function and store in it all inner arrays values
$a = [[1], [2, 3]];
$result = [];
array_walk_recursive($a, function($value) use (&$result)
$result[] = $value;
);
var_dump($result);
add a comment |
OP asks about merging arrays from one array. We don't know how many arrays there, so we need to use array_walk_recursive function. Pass $result from public scope by reference(!) in anonymous function and store in it all inner arrays values
$a = [[1], [2, 3]];
$result = [];
array_walk_recursive($a, function($value) use (&$result)
$result[] = $value;
);
var_dump($result);
add a comment |
OP asks about merging arrays from one array. We don't know how many arrays there, so we need to use array_walk_recursive function. Pass $result from public scope by reference(!) in anonymous function and store in it all inner arrays values
$a = [[1], [2, 3]];
$result = [];
array_walk_recursive($a, function($value) use (&$result)
$result[] = $value;
);
var_dump($result);
OP asks about merging arrays from one array. We don't know how many arrays there, so we need to use array_walk_recursive function. Pass $result from public scope by reference(!) in anonymous function and store in it all inner arrays values
$a = [[1], [2, 3]];
$result = [];
array_walk_recursive($a, function($value) use (&$result)
$result[] = $value;
);
var_dump($result);
edited Mar 22 at 9:36
answered Mar 22 at 8:52
Roman AngelovskijRoman Angelovskij
714
714
add a comment |
add a comment |
Why call_user_func?
$a = array(14);
$b = array(18);
$merged = array_merge($a,$b);
I have array in single variable as $var Array ( [0] => 14 ) Array ( [0] => 18 )
– Amod Kumar
Mar 22 at 8:29
i have used above code as recommended by u but not working for me.
– Amod Kumar
Mar 22 at 8:29
add a comment |
Why call_user_func?
$a = array(14);
$b = array(18);
$merged = array_merge($a,$b);
I have array in single variable as $var Array ( [0] => 14 ) Array ( [0] => 18 )
– Amod Kumar
Mar 22 at 8:29
i have used above code as recommended by u but not working for me.
– Amod Kumar
Mar 22 at 8:29
add a comment |
Why call_user_func?
$a = array(14);
$b = array(18);
$merged = array_merge($a,$b);
Why call_user_func?
$a = array(14);
$b = array(18);
$merged = array_merge($a,$b);
answered Mar 22 at 8:26
PaflowPaflow
426626
426626
I have array in single variable as $var Array ( [0] => 14 ) Array ( [0] => 18 )
– Amod Kumar
Mar 22 at 8:29
i have used above code as recommended by u but not working for me.
– Amod Kumar
Mar 22 at 8:29
add a comment |
I have array in single variable as $var Array ( [0] => 14 ) Array ( [0] => 18 )
– Amod Kumar
Mar 22 at 8:29
i have used above code as recommended by u but not working for me.
– Amod Kumar
Mar 22 at 8:29
I have array in single variable as $var Array ( [0] => 14 ) Array ( [0] => 18 )
– Amod Kumar
Mar 22 at 8:29
I have array in single variable as $var Array ( [0] => 14 ) Array ( [0] => 18 )
– Amod Kumar
Mar 22 at 8:29
i have used above code as recommended by u but not working for me.
– Amod Kumar
Mar 22 at 8:29
i have used above code as recommended by u but not working for me.
– Amod Kumar
Mar 22 at 8:29
add a comment |
you can use
array_merge
– Ramesh Kumar
Mar 22 at 8:27
1
Code, not php version.
– u_mulder
Mar 22 at 8:37
1
3v4l.org/L6cEJ your error is somewhere else. Enable error reporting and check.
– u_mulder
Mar 22 at 8:41
1
@AmodKumar we don't need your scenario, we need exact code which is NOT working.
– u_mulder
Mar 22 at 8:45
2
I think the array posted is created in a loop and he tries to merge after the loop. That is why he has two seperate arrays in the outpiut
– Andreas
Mar 22 at 8:47