PHP code example of wboyz / laravel-enum
1. Go to this page and download the library: Download wboyz/laravel-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/ */
wboyz / laravel-enum example snippets
use WBoyz\LaravelEnum\BaseEnum;
class Fruits extends BaseEnum
{
const APPLE = 1;
const PEACH = 2;
const PEAR = 3;
}
...
$values = Fruits::getValues();
// [1, 2, 3]
$keys = Fruits::getKeys();
// ['APPLE', 'PEACH', 'PEAR']
$dictionary = Fruits::toDictionary();
// ['APPLE' => 1, 'PEACH' => 2, 'PEAR' => 3]
$result = Fruits::hasValue(1);
// true
$result = Fruits::hasKey('APPLE');
// true
$result = Fruits::getValue('APPLE');
// 1
$result = Fruits::getValue('MELON');
// 0