note 128885 added to language.enumerations.static-methods

From: Date: Thu, 14 Sep 2023 13:21:27 +0000
Subject: note 128885 added to language.enumerations.static-methods
Groups: php.notes 
Request: Send a blank email to php-notes+get-220845@lists.php.net to get a copy of this message
You simply need to use the following code as a replacement for the example provided by Aaron Saray. This piece of code is more concise. <?php enum Suit: string { case Hearts = 'H'; case Diamonds = 'D'; case Clubs = 'C'; case Spades = 'S'; public static function forSelect(): array { return array_column(self::cases(), 'name', 'value'); } } var_dump(Suit::forSelect()); ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 2604:a840:3::206d) ---- Manual Page -- https://php.net/manual/en/language.enumerations.static-methods.php Edit -- https://main.php.net/note/edit/128885 Del: integrated -- https://main.php.net/note/delete/128885/integrated Del: useless -- https://main.php.net/note/delete/128885/useless Del: bad code -- https://main.php.net/note/delete/128885/bad+code Del: spam -- https://main.php.net/note/delete/128885/spam Del: non-english -- https://main.php.net/note/delete/128885/non-english Del: in docs -- https://main.php.net/note/delete/128885/in+docs Del: other reasons-- https://main.php.net/note/delete/128885 Reject -- https://main.php.net/note/reject/128885 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220845) next »