note 124580 added to control-structures.switch

From: Date: Wed, 08 Jan 2020 17:15:04 +0000
Subject: note 124580 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-213811@lists.php.net to get a copy of this message
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'; ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.195 (proxied: 195.230.115.34) ---- Manual Page -- http://php.net/manual/en/control-structures.switch.php Edit -- https://master.php.net/note/edit/124580 Del: integrated -- https://master.php.net/note/delete/124580/integrated Del: useless -- https://master.php.net/note/delete/124580/useless Del: bad code -- https://master.php.net/note/delete/124580/bad+code Del: spam -- https://master.php.net/note/delete/124580/spam Del: non-english -- https://master.php.net/note/delete/124580/non-english Del: in docs -- https://master.php.net/note/delete/124580/in+docs Del: other reasons-- https://master.php.net/note/delete/124580 Reject -- https://master.php.net/note/reject/124580 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#213811) next »