Created
November 18, 2015 10:47
-
-
Save arth2o/ddea572706905c7cac81 to your computer and use it in GitHub Desktop.
Flatten an array of arbitrarily nested arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$arr = [[1,2,[3]],4]; | |
$newArr = array(); | |
foreach( (new RecursiveIteratorIterator(new RecursiveArrayIterator($arr))) as $val) { | |
$newArr[] = $val; | |
} | |
var_dump($newArr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment