note 124580 deleted from control-structures.switch by crell

From: Date: Mon, 27 Jun 2022 21:54:54 +0000
Subject: note 124580 deleted from control-structures.switch by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218650@lists.php.net to get a copy of this message
Note Submitter: sergey at neskhodovskiy dot com ---- As the doc states, switch uses loose comparison by default. We use the inversion trick (mentioned by many posters) to make it perform a strict one: $a = 0; switch (true) { case ($a === true): echo '$a is true'; break; case ($a === false): echo '$a is false'; break; case ($a === 0): echo '$a is 0'; break; } // outputs correctly '$a is 0';

« previous php.notes (#218650) next »