Skip to content

Instantly share code, notes, and snippets.

@arth2o
Created November 18, 2015 10:47
Show Gist options
  • Save arth2o/ddea572706905c7cac81 to your computer and use it in GitHub Desktop.
Save arth2o/ddea572706905c7cac81 to your computer and use it in GitHub Desktop.
Flatten an array of arbitrarily nested arrays
$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