-2
Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [itemid] => 2367
                    [price] => 15.99
                    [timestamp] => 2018-01-14 16:23:03
                    [qty] => 22
                )

        )
    [1] => Array
    (
        [0] => Array
            (

                   [itemid] => 2368
                    [price] => 15.99
                    [timestamp] => 2018-01-14 16:23:01
                    [qty] => 13
            )

    )

etc...

you can see that the 1-level arrays contain another useless array... how to flatten it so instead of a nested array I have this result:

Array
(
    [0] => Array
        (
              [itemid] => 2367
              [price] => 15.99
              [timestamp] => 2018-01-14 16:23:03
              [qty] => 22


        )
    [1] => Array
    (


           [itemid] => 2368
           [price] => 15.99
           [timestamp] => 2018-01-14 16:23:01
           [qty] => 13


    )
Francesco
  • 24,839
  • 29
  • 105
  • 152
  • Possible duplicate of [How to Flatten a Multidimensional Array?](https://stackoverflow.com/questions/1319903/how-to-flatten-a-multidimensional-array) – Sean Francis N. Ballais Jan 14 '18 at 16:28
  • 3
    You have 10k score but your question doesn't feature any discussion of what you've tried already and why it didn't work. Your question doesn't show what sort of format you'd like the answer in, do you preserve keys? What reason do you need to flatten it? etc. etc. – Martin Jan 14 '18 at 16:30
  • @SeanFrancisN.Ballais no, is not. – Francesco Jan 14 '18 at 16:30
  • 1
    ***WHY*** is it not a duplicate? – Martin Jan 14 '18 at 16:31
  • 1
    @Martin StackOverflow is the most idiotic reputation system ever invented, as it rewards popular stupid questions and daily visits, so I still don't understand why you even bring it to the discussion – Francesco Jan 14 '18 at 16:31
  • @Martin because I tried those solutions and do not work in my case – Francesco Jan 14 '18 at 16:32
  • I would hope your score is an indicator of your knowledge of how SO works; you're not a beginner here, you've asked many questions and given many answers... so why do you feel this poorly written question deserves to be answered? – Martin Jan 14 '18 at 16:33
  • 1
    If you tried those solutions **SAY THAT IN YOUR QUESTION**. We can only know what you tell us. – Martin Jan 14 '18 at 16:33
  • Did you solve this ? If yes please share how ? – Niklesh Raut Jan 22 '18 at 18:25

1 Answers1

0

You can just try any loop like array_map which return first element like $elem[0]

<?php
$multi = [[[1,2]],[[3,4]],[[5,6]]];
$flat = array_map(function($e){return $e[0];},$multi);
print_r($flat);
?>

Live demo : https://eval.in/934753

Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109