When developing web applications, you probably encounter a lot of places where someone needs to select one or more options in a select or multi-select. These select boxes always need a list of options with labels and values. In one of our projects, we had options being generated in lots of places.
For example, let's say you have an enum like this: enum Hobbit: string { case Frodo = 'frodo'; case Sam = 'sam'; case Merry = 'merry'; case Pippin = 'pippin'; } You can easily convert this to a list of options like this: Options::forEnum(Hobbit::class)->toArray(); Which will return the following array: [['label' => 'Frodo', 'value' => 'frodo'], ['label' => 'Sam', 'value' => 'sam'], ['label' => 'Merry', 'value' => 'merry'], ['label' => 'Pippin', 'value' => 'pippin'], ]