Skip to content

Instantly share code, notes, and snippets.

@arodbits
Created October 3, 2016 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arodbits/491a86de1408a4ba963dec894d8de783 to your computer and use it in GitHub Desktop.
Save arodbits/491a86de1408a4ba963dec894d8de783 to your computer and use it in GitHub Desktop.
Create a collection of nested arrays recursively in Laravel 5.x
<?php
function collect_recursive($value)
{
if (is_array($value)) {
$c = collect($value);
}
$collection = $c->map(function ($item, $key) {
if (is_array($item)) {
return collect_recursive($item);
}
});
return $collection;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment