match类似switch
下面是switch
$bool = false;
switch ($bool) {
case false: $result = 10;
break;
case true: $result = 20;
break;
default: $result = 30;
}
var_dump($result);
![输出10](https://i-blog.csdnimg.cn/blog_migrate/737d5d6d5400c19b43896cfba2551d1b.png)
下面是match
$bool = false;
$result = match($bool) {
false => 30,
true => 40,
};
var_dump($result);
![输出30](https://i-blog.csdnimg.cn/blog_migrate/46efeb2d85a81d14b47059ed8919b610.png)