Created
September 10, 2013 19:54
-
-
Save kriswallsmith/6514704 to your computer and use it in GitHub Desktop.
I could really go for an array_index() function right now.
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 | |
$widgets = array_combine( | |
array_map( | |
function($widget) { | |
return $widget->getId(); | |
}, | |
$widgets | |
), | |
$widgets | |
); |
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 | |
$widgets = array_index(function($widget) { | |
return $widget->getId(); | |
}, $widgets); |
Shameless plug!
You should try my ArrayTools package: https://github.com/axelarge/php-array-tools
Available via composer: https://packagist.org/packages/axelarge/array-tools
$widgets = Arr::indexBy($widgets, function ($widget) { return $widget->getId(); });
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After-after :)