PHP code example of fatihirday / enummethods

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

    

fatihirday / enummethods example snippets




use Fatihirday\EnumMethods\EnumMethods;

enum HttpMethods: string
{
    use EnumMethods;

    case GET = 'get';
    case POST = 'post';
}



HttpMethods::names();

// Array
// (
//     [0] => GET
//     [1] => POST
// )


HttpMethods::names(operator: ', ');

// GET, POST




HttpMethods::values();

// Array
// (
//     [0] => get
//     [1] => post
// )


HttpMethods::values(operator: ', ');

// get, post




HttpMethods::toArray();

//    Array
//    (
//        [GET] => get
//        [POST] => post
//    )


HttpMethods::toArray(reverse: true);

//    Array
//    (
//        [get] => GET
//        [post] => POST
//    )




HttpMethods::toObject();

//    Object
//    (
//        get => GET
//        post => POST
//    )


HttpMethods::toObject(reverse: true);

//    Object
//    (
//        get => GET
//        post => POST
//    )




HttpMethods::getValueByName('GET');

//    get


HttpMethods::getNameByValue('get');

//    GET




HttpMethods::tryFromName('GET');

//    True