PHP code example of skinka / type-enum

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

    

skinka / type-enum example snippets




namespace skinka\php\TypeEnum\enums;

use skinka\php\TypeEnum\BaseEnum;

/**
 * Class to enumerations of YES or NO status
 *
 * @method static YesNo YES()
 * @method static YesNo NO()
 * @method string text()
 */

class YesNo extends BaseEnum
{
    const YES = 1;
    const NO = 0;

    public static function getData() {
        return [
            self::YES => [
                'text' => 'Yes',
            ],
            self::NO => [
                'text' => 'No',
            ]
        ];
    }
}

YesNo::getDataList(); //[0 => 'No', 1 => 'Yes']

YesNo::getKeys(); //[0,1]

YesNo::NO(); //0

YesNo::YES()->text(); //Yes

YesNo::YES()->getValue(); //1

YesNo::YES()->getArray(); //['text' => 'Yes']

YesNo::getByValue(0)->text(); //No

YesNo::getByName('YES'); //1