note 110101 added to language.expressions

From: Date: Wed, 19 Sep 2012 13:48:58 +0000
Subject: note 110101 added to language.expressions
Groups: php.notes 
Request: Send a blank email to php-notes+get-190881@lists.php.net to get a copy of this message
Clarification about the multiply (star) character: Note that if you try to use the '*' in a comparaison you will have many results... <?php $a = '*'; switch($a) { case 1: echo ' (int)one'; case 0: echo ' (int)zero'; case '0': echo ' (string)zero'; case '*': echo ' (string)star'; case true: echo ' (bool)true'; case false: echo ' (bool)false'; } // ouput // (int)zero (string)zero (string)star (bool)true (bool)false ?> The reason this code outputs "(int)zero (string)zero (string)star (bool)true (bool)false" is we didn't put "break" statement into each "case" The reason we start from "(int)zero ..." is php switch operator works with loose comparison, so <?php '*' == 0 //true ('*' converted in number - 0) ?> Worth to mention <?php '*' == 1 //false '*' == 0 //true '*' == '0' //false '*' == '*' //true '*' == true //true '*' == false //false ?> Hope this makes the note below clear. ---- Server IP: 69.147.83.197 Probable Submitter: 109.86.160.59 ---- Manual Page -- http://www.php.net/manual/en/language.expressions.php Edit -- https://master.php.net/note/edit/110101 Del: integrated -- https://master.php.net/note/delete/110101/integrated Del: useless -- https://master.php.net/note/delete/110101/useless Del: bad code -- https://master.php.net/note/delete/110101/bad+code Del: spam -- https://master.php.net/note/delete/110101/spam Del: non-english -- https://master.php.net/note/delete/110101/non-english Del: in docs -- https://master.php.net/note/delete/110101/in+docs Del: other reasons-- https://master.php.net/note/delete/110101 Reject -- https://master.php.net/note/reject/110101 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190881) next »