PHP code example of kalibora / labeled-enum

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

    

kalibora / labeled-enum example snippets


use Kalibora\LabeledEnum\LabeledEnum;

class Fruit extends LabeledEnum
{
    private const APPLE = 1;
    private const ORANGE = 2;
    private const BANANA = 3;

    public static function getLabels() : array
    {
        return [
            self::APPLE => 'Apple',
            self::ORANGE => 'Orange',
            self::BANANA => 'Banana',
        ];
    }
}

$orange = Fruit::ORANGE();

echo $orange->getValue(), PHP_EOL; // 2
echo $orange->getLabal(), PHP_EOL; // Orange