Added array_pluck method.

This commit is contained in:
Taylor Otwell 2012-04-27 14:26:46 -05:00
parent e9bcbeac8f
commit 68d9210ef5
2 changed files with 18 additions and 0 deletions

View File

@ -63,6 +63,8 @@ ## Laravel 3.2
- Added `Input::replace` method. - Added `Input::replace` method.
- Added saving, saved, updating, creating, deleting, and deleted events to Eloquent. - Added saving, saved, updating, creating, deleting, and deleted events to Eloquent.
- Added new `Sectionable` interface to allow cache drivers to simulate namespacing. - Added new `Sectionable` interface to allow cache drivers to simulate namespacing.
- Added support for `HAVING` SQL clauses.
- Added `array_pluck` helper, similar to pluck method in Underscore.js.
<a name="upgrade-3.2"></a> <a name="upgrade-3.2"></a>
## Upgrading From 3.1 ## Upgrading From 3.1

View File

@ -229,6 +229,22 @@ function array_divide($array)
return array(array_keys($array), array_values($array)); return array(array_keys($array), array_values($array));
} }
/**
* Pluck an array of values from an array.
*
* @param array $array
* @param string $key
* @return array
*/
function array_pluck($array, $key)
{
return array_map(function($v)
{
return is_object($v) ? $v->$key : $v[$key];
}, $array);
}
/** /**
* Determine if "Magic Quotes" are enabled on the server. * Determine if "Magic Quotes" are enabled on the server.
* *