Source Code:
(back to article)
<?php $input_array = [1, 2, [3, 4, [5, 6]], [7, 8]]; $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($input_array)); $flattened_array = iterator_to_array($iterator, false); print_r($flattened_array); // Output: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 )
Result:
Report an issue