File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,28 @@ returns
157157]
158158```
159159
160+ ### map
161+
162+ Returns an array of all enum values mapping to their label.
163+
164+ #### Usage
165+
166+ ``` php
167+ VolumeUnitEnum::map();
168+ ```
169+
170+ returns
171+
172+ ``` php
173+ [
174+ 'MILLIGRAM'=>'mg',
175+ 'GRAM' =>'g',
176+ 'KILOGRAM' =>'kg',
177+ 'TONNE' =>'t',
178+ ]
179+ ```
180+
181+
160182### labelFor
161183
162184Returns the label for a given enum name.
Original file line number Diff line number Diff line change @@ -27,6 +27,18 @@ public static function values(): array
2727 return array_map (fn ($ enum ) => $ enum ->name , self ::cases ());
2828 }
2929
30+ public static function map (): array
31+ {
32+ static ::ensureImplementsInterface ();
33+ $ array = [];
34+
35+ foreach (self ::cases () as $ enum ) {
36+ $ array [$ enum ->name ] = $ enum ->label ();
37+ }
38+
39+ return $ array ;
40+ }
41+
3042 public static function labels (): array
3143 {
3244 static ::ensureImplementsInterface ();
You can’t perform that action at this time.
0 commit comments