PHP code example of commitglobal / enum-utils

1. Go to this page and download the library: Download commitglobal/enum-utils 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/ */

    

commitglobal / enum-utils example snippets


enum Status: string
{
    use CommitGlobal\Enums\Concerns\Arrayable;

    case ACTIVE = 'active';
    case INACTIVE = 'inactive';

    public function getLabel(): string
    {
        return match($this) {
            self::ACTIVE => 'Account is active',
            self::INACTIVE => 'Account is inactive',
        };
    }
}

Status::names();   // ['ACTIVE', 'INACTIVE']
Status::values();  // ['active', 'inactive']
Status::options(); // ['active' => 'Account is active', 'inactive' => 'Account is inactive']

enum Status: string
{
    use CommitGlobal\Enums\Concerns\Comparable;

    case ACTIVE = 'active';
    case INACTIVE = 'inactive';
}

$status = Status::ACTIVE;

$status->is(Status::ACTIVE);   // true
$status->is('active');         // true
$status->is(Status::INACTIVE); // false
$status->isNot('inactive');    // true