Skip to content

Instantly share code, notes, and snippets.

@filippomangione
Created May 4, 2014 10:06
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 filippomangione/db5489c5dea0622a3774 to your computer and use it in GitHub Desktop.
Save filippomangione/db5489c5dea0622a3774 to your computer and use it in GitHub Desktop.
An equivalent to Underscore.js pluck method.
<?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