note 128911 added to language.enumerations.static-methods

From: Date: Fri, 22 Sep 2023 07:06:34 +0000
Subject: note 128911 added to language.enumerations.static-methods
Groups: php.notes 
Request: Send a blank email to php-notes+get-220870@lists.php.net to get a copy of this message
If you want to supplement the key-value pairs with additional descriptions for each enum value in the forSelect method, you can modify the array structure to include an associative array for each enum value. Here's an example: <?php enum Gender:int { case Male = 1; case Female = 2; public static function forSelect(): array { return [ self::Male->value => [ 'label' => 'Male', 'description' => 'This is the Male gender', ], self::Female->value => [ 'label' => 'Female', 'description' => 'This is the Female gender', ], ]; } } ?> In this updated example, each enum value is represented as an associative array with two keys: 'label' and 'description'. You can customize the label and description for each enum value accordingly. Please note that to access the label and description for a specific enum value, you would need to use the corresponding array keys. For example, to get the label for the Male gender, you can use self::forSelect()[self::Male->value]['label']. ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 197.38.70.80) ---- Manual Page -- https://php.net/manual/en/language.enumerations.static-methods.php Edit -- https://main.php.net/note/edit/128911 Del: integrated -- https://main.php.net/note/delete/128911/integrated Del: useless -- https://main.php.net/note/delete/128911/useless Del: bad code -- https://main.php.net/note/delete/128911/bad+code Del: spam -- https://main.php.net/note/delete/128911/spam Del: non-english -- https://main.php.net/note/delete/128911/non-english Del: in docs -- https://main.php.net/note/delete/128911/in+docs Del: other reasons-- https://main.php.net/note/delete/128911 Reject -- https://main.php.net/note/reject/128911 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220870) next »