PHP code example of ariantron / base-enum
1. Go to this page and download the library: Download ariantron/base-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/ */
ariantron / base-enum example snippets
namespace App\Enums;
use ArianTron\BaseEnum\BaseEnum;
class Numbers extends BaseEnum
{
const ONE = 'one';
const TWO = 'two';
const THREE = 'three';
}
// Check if a name is a valid constant in the Enum
$result = Numbers::isValidName('TWO'); // true
// Get all constants in the Enum
$constants = Numbers::getConstants(); // ['one','two','three']
// Check if a value is a valid constant value in the Enum
$result = Numbers::isValidValue('two'); // true
// Convert a constant value back to its name
$name_1 = Numbers::getName('two'); // 'TWO'
//or
$name_2 = Numbers::getName(Numbers::TWO); // 'TWO'