Created
October 3, 2016 21:07
-
-
Save arodbits/491a86de1408a4ba963dec894d8de783 to your computer and use it in GitHub Desktop.
Create a collection of nested arrays recursively in Laravel 5.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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