note 126843 added to control-structures.match

From: Date: Sat, 12 Feb 2022 06:08:48 +0000
Subject: note 126843 added to control-structures.match
Groups: php.notes 
Request: Send a blank email to php-notes+get-217600@lists.php.net to get a copy of this message
While you can’t polyfill a language construct, you can mimic the basic behaviour with a simple array. Using example 2 above: <?php $food = 'apple'; $return_value = match ($food) { 'apple' => 'This food is an apple', 'bar' => 'This food is a bar', 'cake' => 'This food is a cake', }; print $return_value; ?> … you can get something similar with: <?php $food = 'apple'; $return_value = [ 'apple' => 'This food is an apple', 'bar' => 'This food is a bar', 'cake' => 'This food is a cake', ][$food]; print $return_value; ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 159.196.219.235) ---- Manual Page -- https://php.net/manual/en/control-structures.match.php Edit -- https://main.php.net/note/edit/126843 Del: integrated -- https://main.php.net/note/delete/126843/integrated Del: useless -- https://main.php.net/note/delete/126843/useless Del: bad code -- https://main.php.net/note/delete/126843/bad+code Del: spam -- https://main.php.net/note/delete/126843/spam Del: non-english -- https://main.php.net/note/delete/126843/non-english Del: in docs -- https://main.php.net/note/delete/126843/in+docs Del: other reasons-- https://main.php.net/note/delete/126843 Reject -- https://main.php.net/note/reject/126843 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217600) next »