-1

I've an array like below: I want to make it single array format.

Array
  (
    [0] => Array
    (
        [0] => 0
        [1] => 1
        [2] => 2
        [3] => 3
        [4] => 10
    )

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

Would like to get output like below.

[0] => Array
    (
        [0] => 0
        [1] => 1
        [2] => 2
        [3] => 3
        [4] => 10
    )

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

How can i achieve my preferred format ?? Any help would be appreciated.

6
  • apply foreach() and get the sub-array value. BTW your question is bit unclear. Clarify a bit more pls Commented Apr 30, 2018 at 5:39
  • 3
    Both arrays are the same. Parents keys are 0 and 1 and they have sub arrays the same too. Commented Apr 30, 2018 at 5:40
  • @AlivetoDie, Both are not same, First one is Array within Array, second is that i want to achieve where only single array no parent array. Commented Apr 30, 2018 at 5:42
  • $arr1 = $main[0] and $arr2 = $main[1]? Where $main is the main array you have Commented Apr 30, 2018 at 5:44
  • Refer this stack overflow answer stackoverflow.com/questions/6785355/… Another method is $array = array_column($array, 'plan'); down vote $array = array_column($array, 'plan'); The first argument is an array and the second argument is array key. Commented Apr 30, 2018 at 5:45

1 Answer 1

1

With a foreach() you can easily loop over it

<?php

$array = [
        [0, 1, 2, 3, 10],
        [0, 1, 2, 3]
    ];

foreach ($array as $smallArray)
{
    var_dump($smallArray);
}

Try it out yourself here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.