PHP code example of tkachikov / enum-values
1. Go to this page and download the library: Download tkachikov/enum-values 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/ */
tkachikov / enum-values example snippets
namespace App\Enums;
use Tkachikov\EnumValues\EnumValuesTrait;
class StateEnum: int
{
use EnumValuesTrait;
const ACTIVE = 10;
const BLOCKED = 20;
}
$values = StateEnum::getValues(); // [10, 20]
$keys = StateEnum::getKeys(); // ['ACTIVE', 'BLOCKED']
$arrayByKey = StateEnum::getByKey(); // ['ACTIVE' => 10, 'BLOCKED' => 20]
$arrayByValue = StateEnum::getByValue(); // [10 => 'ACTIVE', 20 => 'BLOCKED']