请问case语句

WBOY
Release: 2016-06-13 13:09:28
Original
767 people have browsed it

请教case语句
$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';

上面这段为什么输出//(int)zero (string)zero (string)star (bool)true (bool)false 
而不是输出//(string)star (bool)true (bool)false

------解决方案--------------------
每一句后面你都没写 break;它就继续匹配下一个case
------解决方案--------------------
因为case是弱类型比较
将字符串与数字比较的时候,字符串会被强制转换成数字

而你这个字符串强制转换后是0

所以就与0相等了

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template