note 126917 added to control-structures.match

From: Date: Fri, 11 Mar 2022 11:27:24 +0000
Subject: note 126917 added to control-structures.match
Groups: php.notes 
Request: Send a blank email to php-notes+get-217709@lists.php.net to get a copy of this message
If you want to execute multiple return expressions when matching a conditional expression, you can do so by stating all return expressions inside an array. <?php $countries = ['Belgium', 'Netherlands']; $spoken_languages = [ 'Dutch' => false, 'French' => false, 'German' => false, 'English' => false, ]; foreach ($countries as $country) { match($country) { 'Belgium' => [ $spoken_languages['Dutch'] = true, $spoken_languages['French'] = true, $spoken_languages['German'] = true, ], 'Netherlands' => $spoken_languages['Dutch'] = true, 'Germany' => $spoken_languages['German'] = true, 'United Kingdom' => $spoken_languages['English'] = true, }; } var_export($spoken_languages); // array ( 'Dutch' => true, 'French' => true, 'German' => true, 'English' => false, ) ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 2a02:1810:3f1c:6100:7c0c:4857:6b9c:7dc6) ---- Manual Page -- https://php.net/manual/en/control-structures.match.php Edit -- https://main.php.net/note/edit/126917 Del: integrated -- https://main.php.net/note/delete/126917/integrated Del: useless -- https://main.php.net/note/delete/126917/useless Del: bad code -- https://main.php.net/note/delete/126917/bad+code Del: spam -- https://main.php.net/note/delete/126917/spam Del: non-english -- https://main.php.net/note/delete/126917/non-english Del: in docs -- https://main.php.net/note/delete/126917/in+docs Del: other reasons-- https://main.php.net/note/delete/126917 Reject -- https://main.php.net/note/reject/126917 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217709) next »