Skip to content

Instantly share code, notes, and snippets.

View filjoseph1989's full-sized avatar
🏠
Working from home

Fil filjoseph1989

🏠
Working from home
View GitHub Profile
@filjoseph1989
filjoseph1989 / flatten.php
Last active July 17, 2016 23:27
Flatten a given array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
<?php
function flatten_array ( $temp = array(), $flatten=array() ) {
foreach ($temp as $key => $value) {
if (is_array($value)) {
$flatten = flatten_array ($value, $flatten);
} else {
$flatten[] = $value;
}
}
return $flatten;