Created
May 4, 2014 10:06
-
-
Save filippomangione/db5489c5dea0622a3774 to your computer and use it in GitHub Desktop.
An equivalent to Underscore.js pluck method.
This file contains hidden or 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 | |
$stooges = [ | |
["name" => "Moe", "age" => 40], | |
["name" => "Larry", "age" => 50], | |
["name" => "Curly", "age" => 60], | |
]; | |
function array_pluck ($toPluck, $arr) { | |
return array_map(function ($item) use ($toPluck) { | |
return $item[$toPluck]; | |
}, $arr); | |
} | |
print_r(array_pluck("name", $stooges)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment