Skip to content

Instantly share code, notes, and snippets.

@woprrr
Created August 20, 2019 07:21
Show Gist options
  • Save woprrr/592bdbb6393bbfe0195ec84260f98185 to your computer and use it in GitHub Desktop.
Save woprrr/592bdbb6393bbfe0195ec84260f98185 to your computer and use it in GitHub Desktop.
flatten array tips
function flatten($items)
{
$result = [];
foreach ($items as $item) {
if (is_array($item)) {
$result = array_merge($result, array_values($item));
continue;
}
$result[] = $item;
}
return $result;
}
$item = [1, 2, 3, [4], 5];
var_dump(flatten($item));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment