PHP 8 匹配表达式代码
echo match (8.0) {
'8.0' => "Oh no!",
8.0 => "This is what I expected",
};
//> This is what I expected
PHP 7 切换代码
switch (8.0) {
case '8.0':
$result = "Oh no!";
break;
case 8.0:
$result = "This is what I expected";
break;
}
echo $result;
//> Oh no!
- 哪一个提供更好的性能?
- 匹配和切换的用例。