0

I am trying to get an array of only values, from an array having different dimensions:

My output array is in the form below

array[
    0 => 1
    1 => array[
    0 => 6
    1 => array[
     0 => 7
     1 => 8
    ]
  ]
]

My required array is in form:-

 array(1, 6, 7, 8)
James Westgate
  • 11,306
  • 8
  • 61
  • 68
Pawan Dongol
  • 1,098
  • 3
  • 16
  • 32
  • Duplicate of https://stackoverflow.com/questions/526556/how-to-flatten-a-multi-dimensional-array-to-simple-one-in-php – Vincent Decaux Jul 20 '20 at 08:07
  • Does this answer your question? [How to "flatten" a multi-dimensional array to simple one in PHP?](https://stackoverflow.com/questions/526556/how-to-flatten-a-multi-dimensional-array-to-simple-one-in-php) – scrimau Jul 20 '20 at 08:18
  • Thank as lot @VincentDecaux, I solve my issue from your provided link. – Pawan Dongol Jul 20 '20 at 08:33

1 Answers1

0

How to Flatten a Multidimensional Array?

You can use the Standard PHP Library (SPL) to "hide" the recursion.

$a = array(1,2,array(3,4, array(5,6,7), 8), 9);
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($a));
foreach($it as $v) {
  echo $v, " ";
}
vahid
  • 11
  • 4