PHP code example of salekur / enum

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

    

salekur / enum example snippets


namespace Salekur\Enum\Enum;

class UserRole extends Enum {
    const ADMIN = 'admin';
    const EDITOR = 'editor';
    const VIEWER = 'viewer';

    // optional values function
    public static function values(): array {
        return [
            self::ADMIN => 'Administrator',
            self::EDITOR => 'Content Editor',
            self::VIEWER => 'Content Viewer'
        ];
    }
}

$options = UserRole::options();
// ['admin' => 'Administrator', 'editor' => 'Content Editor', 'viewer' => 'Content Viewer']

$label = UserRole::get('admin');
// 'Administrator'

$exists = UserRole::has('editor');
// true

$keys = UserRole::keys();
// ['admin', 'editor', 'viewer']

$labels = UserRole::labels();
// ['Administrator', 'Content Editor', 'Content Viewer']