1
0
Fork 0
mirror of https://github.com/archtechx/enums.git synced 2025-12-12 11:14:05 +00:00

use array_column() to get the names, values, and options

This commit is contained in:
Eric Junker 2022-02-20 20:45:55 -06:00
parent c733871aaa
commit 10b68d7b39
3 changed files with 3 additions and 11 deletions

View file

@ -9,8 +9,6 @@ trait Names
/** Get an array of case names. */ /** Get an array of case names. */
public static function names(): array public static function names(): array
{ {
return array_map(function ($case) { return array_column(static::cases(), 'name');
return $case->name;
}, static::cases());
} }
} }

View file

@ -9,10 +9,6 @@ trait Options
/** Get an associative array of [case name => case value]. */ /** Get an associative array of [case name => case value]. */
public static function options(): array public static function options(): array
{ {
return array_reduce(static::cases(), function ($options, $case) { return array_column(static::cases(), 'value', 'name');
$options[$case->name] = $case->value;
return $options;
}, []);
} }
} }

View file

@ -9,8 +9,6 @@ trait Values
/** Get an array of case values. */ /** Get an array of case values. */
public static function values(): array public static function values(): array
{ {
return array_map(function ($case) { return array_column(static::cases(), 'value');
return $case->value;
}, static::cases());
} }
} }