note 110101 deleted from language.expressions by googleguy
| From: | googleguy@php.net | Date: | Thu, 20 Sep 2012 00:28:34 +0000 |
| Subject: | note 110101 deleted from language.expressions by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190893@lists.php.net to get a copy of this message | ||
Note Submitter: sutok85 at gmail dot com
----
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.