-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.

anonymous
  • 127
  • 1
  • 8
  • apply `foreach()` and get the sub-array value. BTW your question is bit unclear. Clarify a bit more pls – Alive to die - Anant Apr 30 '18 at 05:39
  • 3
    Both arrays are the same. Parents keys are `0` and `1` and they have sub arrays the same too. – Himanshu Upadhyay Apr 30 '18 at 05: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. – anonymous Apr 30 '18 at 05:42
  • `$arr1 = $main[0]` and `$arr2 = $main[1]`? Where `$main` is the main array you have – Eddie Apr 30 '18 at 05:44
  • Refer this stack overflow answer https://stackoverflow.com/questions/6785355/convert-multidimensional-array-into-single-array 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. – Robert Apr 30 '18 at 05:45
  • You cant have multiple "single" arrays in 1 variable without a parent array, sorry just doesn't work that way. – ArtisticPhoenix Apr 30 '18 at 05:50

1 Answers1

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

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
ThomasVdBerge
  • 7,483
  • 4
  • 44
  • 62