Skip to content

Instantly share code, notes, and snippets.

@MohammedAttya2
Created March 5, 2018 10:19
Show Gist options
  • Save MohammedAttya2/fe82e6f2d73f7e8f0074ea8e3ca2692a to your computer and use it in GitHub Desktop.
Save MohammedAttya2/fe82e6f2d73f7e8f0074ea8e3ca2692a to your computer and use it in GitHub Desktop.
<?php
/**
* Collapse an array of arrays into a single array.
*
* @param array $array
* @return array
*/
public static function collapse($array)
{
$results = [];
foreach ($array as $values) {
if ($values instanceof Collection) {
$values = $values->all();
} elseif (! is_array($values)) {
continue;
}
$results = array_merge($results, $values);
}
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment