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;








-5















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);









share|improve this question















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
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • 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

















-5















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);









share|improve this question















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
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • 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













-5












-5








-5








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);









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
If this question can be reworded to fit the rules in the help center, please edit the question.







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
If this question can be reworded to fit the rules in the help center, please edit the question.












  • 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

















  • 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
















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












4 Answers
4






active

oldest

votes


















1














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






share|improve this answer

























  • 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



















0














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
)





share|improve this answer






























    0














    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);





    share|improve this answer
































      -1














      Why call_user_func?



      $a = array(14);
      $b = array(18);
      $merged = array_merge($a,$b);





      share|improve this answer























      • 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


















      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      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






      share|improve this answer

























      • 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
















      1














      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






      share|improve this answer

























      • 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














      1












      1








      1







      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






      share|improve this answer















      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







      share|improve this answer














      share|improve this answer



      share|improve this answer








      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


















      • 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














      0














      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
      )





      share|improve this answer



























        0














        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
        )





        share|improve this answer

























          0












          0








          0







          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
          )





          share|improve this answer













          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
          )






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 8:27









          RamRaiderRamRaider

          18.7k31935




          18.7k31935





















              0














              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);





              share|improve this answer





























                0














                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);





                share|improve this answer



























                  0












                  0








                  0







                  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);





                  share|improve this answer















                  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);






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 22 at 9:36

























                  answered Mar 22 at 8:52









                  Roman AngelovskijRoman Angelovskij

                  714




                  714





















                      -1














                      Why call_user_func?



                      $a = array(14);
                      $b = array(18);
                      $merged = array_merge($a,$b);





                      share|improve this answer























                      • 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
















                      -1














                      Why call_user_func?



                      $a = array(14);
                      $b = array(18);
                      $merged = array_merge($a,$b);





                      share|improve this answer























                      • 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














                      -1












                      -1








                      -1







                      Why call_user_func?



                      $a = array(14);
                      $b = array(18);
                      $merged = array_merge($a,$b);





                      share|improve this answer













                      Why call_user_func?



                      $a = array(14);
                      $b = array(18);
                      $merged = array_merge($a,$b);






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      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


















                      • 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




                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현