PHP code example of upward / enumerables
1. Go to this page and download the library: Download upward/enumerables 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/ */
upward / enumerables example snippets
use Upward\Enumerables\Attributes\Label;
use Upward\Enumerables\Traits\InteractsWithLabel;
enum Status
{
use InteractsWithLabel;
#[Label(text: 'Active')]
case ACTIVE;
#[Label(text: 'Inactive')]
case INACTIVE;
}
// Accessing the label text
$status = Status::ACTIVE;
echo $status->getLabel(); // Outputs: Active
use Upward\Enumerables\Attributes\Label;
use Upward\Enumerables\Traits\InteractsWithLabel;
enum UserRole
{
use InteractsWithLabel;
#[Label(text: 'Administrator', translate: false)]
case ADMIN;
#[Label(text: 'Editor', translate: false)]
case EDITOR;
}
$role = UserRole::ADMIN;
echo $role->getLabel(); // Outputs: Administrator