Retrieves muliple single-key values from a list of arrays.
// Get all of the "id" values from a result
$ids = Arr::pluck($result, 'id');
array Core_Arr::pluck( array $array , string $key )
参数列表
参数 类型 描述 默认值 $array
array
List of arrays to check $key
string
Key to pluck
array
public static function pluck($array, $key)
{
$values = array();
foreach ($array as $row)
{
if (isset($row[$key]))
{
// Found a value in this row
$values[] = $row[$key];
}
}
return $values;
}