Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to convert enum to string in php

Do it your self without of magic ! ;-) We have PHP 8.1 now.

enum DataType: string {
    case ACCEPTED = "accepted";
    case WITH_ERRORS = "with errore";
    case DONE = "done";
    case FAILED ='failed';

    public function toString(): string {
      return match($this){
        self::ACCEPTED => 'Accepted',
        self::WITH_ERRORS => 'With Errors',
        self::DONE  => 'Done',
        self::FAILED  => 'Failed',
        default => '',
      };
    }
}

echo DataType::DONE->toString();
Comment

PREVIOUS NEXT
Code Example
Php :: lastinsertId php 
Php :: resize image using intervention laravel and save 
Php :: laravel sanctum Provoking tokens 
Php :: Securing form from possible sql injection 
Php :: PHP rtrim — Strip whitespace (or other characters) from the end of a string 
Php :: Automatic Subdomain with PHP 
Php :: php explode sentence into words 
Php :: doctrine getrepository findby 
Php :: get users by role name - spatie/laravel-permission 
Php :: laravel custom abort message 
Php :: change php version on ubuntu 
Php :: laravel where and blade 
Php :: codeigniter select where 
Php :: how to add javascript to a php variable 
Php :: naming convention for magento2 custom cms page index xml file 
Php :: laravel isset 
Php :: loginByUserID in conrete 
Php :: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar://D:/Program Files/Composer - PHP/composer.phar/src/Composer/DependencyResolver/Solver.php on line 223 
Php :: Update page template and remove page editor in wordpress 
Php :: php encrypt password 
Php :: php assign an array inside a foreach loop 
Php :: conditional validation laravel based on role 
Php :: order by pre get posts 
Php :: php pass 2 date value to javascript 
Php :: laravel getClientOriginalExtension 
Php :: php pagination ellipsis 
Php :: php ini_set 
Php :: select statement of table in phpmyadmin 
Php :: php $_server 
Php :: use htaccess to redirect in cpanel laravel 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =