PHP code example of miladrahimi / php-enum

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

    

miladrahimi / php-enum example snippets


namespace MiladRahimi\Enum\Enum;

class SampleEnum extends Enum
{
    const UNO = 1;
    const ONE = 1;
    const TWO = 2;
    const STR = "sth";
}

SampleEnum::all(); // ['UNO' => 1, 'ONE' => 1, 'TWO' => 2, 'STR' => 'sth']

SampleEnum::keys(); // ['UNO', 'ONE', 'TWO', 'STR'];

SampleEnum::values(); // [1, 1, 2, 'sth']

SampleEnum::hasKey('ONE'); // true

SampleEnum::hasKey('xXx'); // false

SampleEnum::hasValue(2); // true

SampleEnum::hasValue('xXx'); // false

SampleEnum::valueOf('ONE'); // 1

SampleEnum::keysOf(1); // ['UNO', 'ONE']

SampleEnum::keyOf(1); // 'UNO'

SampleEnum::randomKey(); // One of 'UNO', 'ONE', 'TWO', 'STR'

SampleEnum::randomKeyExceptKeys(['ONE', 'TWO']); // One of 'UNO', 'STR'

SampleEnum::randomKeyExceptValues([SampleEnum::STR, SampleEnum::TWO]); // One of 'ONE', 'UNO'

SampleEnum::randomValue(); // One of 1, 2, 'sth'

SampleEnum::randomValueExceptValues([SampleEnum::STR, SampleEnum::TWO]); // One of SampleEnum::ONE, SampleEnum::UNO

SampleEnum::randomValueExceptKeys(['STR', 'TWO']); // One of SampleEnum::ONE, SampleEnum::UNO

composer