PHP code example of outerweb / enum-helpers

1. Go to this page and download the library: Download outerweb/enum-helpers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

outerweb / enum-helpers example snippets


use Outerweb\EnumHelpers\HasCollectionSupport;

enum MyEnum: string
{
    use HasCollectionSupport;

    case Foo = 'foo';
    case Bar = 'bar';

    public function getLabel(): string
    {
        return match ($this) {
            self::Foo => 'Foo label',
            self::Bar => 'Bar label',
        };
    }
}

$collection = MyEnum::collect(); // Collection{'foo' => MyEnum::Foo, 'bar' => MyEnum::Bar}

$values = MyEnum::collect('value'); // Collection{'foo' => 'foo', 'bar' => 'bar'}

$mapped = MyEnum::collect('getLabel'); // Collection{'foo' => 'Foo label', 'bar' => 'Bar label'}