mirror of
https://github.com/archtechx/enums.git
synced 2025-12-12 06:44:04 +00:00
use array_column() to get the names, values, and options
This commit is contained in:
parent
c733871aaa
commit
10b68d7b39
3 changed files with 3 additions and 11 deletions
|
|
@ -9,8 +9,6 @@ trait Names
|
|||
/** Get an array of case names. */
|
||||
public static function names(): array
|
||||
{
|
||||
return array_map(function ($case) {
|
||||
return $case->name;
|
||||
}, static::cases());
|
||||
return array_column(static::cases(), 'name');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,6 @@ trait Options
|
|||
/** Get an associative array of [case name => case value]. */
|
||||
public static function options(): array
|
||||
{
|
||||
return array_reduce(static::cases(), function ($options, $case) {
|
||||
$options[$case->name] = $case->value;
|
||||
|
||||
return $options;
|
||||
}, []);
|
||||
return array_column(static::cases(), 'value', 'name');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ trait Values
|
|||
/** Get an array of case values. */
|
||||
public static function values(): array
|
||||
{
|
||||
return array_map(function ($case) {
|
||||
return $case->value;
|
||||
}, static::cases());
|
||||
return array_column(static::cases(), 'value');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue