note 129787 added to control-structures.match

From: Date: Tue, 01 Oct 2024 08:50:19 +0000
Subject: note 129787 added to control-structures.match
Groups: php.notes 
Request: Send a blank email to php-notes+get-221572@lists.php.net to get a copy of this message
Example 3, contains an error In this example, when the age is 48, the out will still be "Young adult" and not "Old adult" the function returns the value at the first valid match. <?php $age = 48; $output = match (true) { $age < 2 => "Baby", $age < 13 => "Child", $age <= 19 => "Teenager", $age > 19 => "Young adult", $age >= 40 => "Old adult" }; var_dump($output); ?> It should be <?php $age = 48; $output = match (true) { $age < 2 => "Baby", $age < 13 => "Child", $age <= 19 => "Teenager", $age >= 40 => "Old adult", $age > 19 => "Young adult", }; var_dump($output); ?> to get the right outpur. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 2a02:a443:a79e:1:10b2:2b9:b8af:2a10) ---- Manual Page -- https://php.net/manual/en/control-structures.match.php Edit -- https://main.php.net/note/edit/129787 Del: integrated -- https://main.php.net/note/delete/129787/integrated Del: useless -- https://main.php.net/note/delete/129787/useless Del: bad code -- https://main.php.net/note/delete/129787/bad+code Del: spam -- https://main.php.net/note/delete/129787/spam Del: non-english -- https://main.php.net/note/delete/129787/non-english Del: in docs -- https://main.php.net/note/delete/129787/in+docs Del: other reasons-- https://main.php.net/note/delete/129787 Reject -- https://main.php.net/note/reject/129787 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221572) next »