Source Code:
(back to article)
<?php function flatten_array($array) { $flat = []; foreach ($array as $value) { if (is_array($value)) { $flat = array_merge($flat, flatten_array($value)); } else { $flat[] = $value; } } return $flat; } $multiDimensionalArray = [1, [2, 3], [4, [5, 6]]]; $flattenedArray = flatten_array($multiDimensionalArray); print_r($flattenedArray);
Result:
Report an issue