1 match 表达式 (错误类型可以无变量)
$id = $this->request->post('id/d');
try{
$sid = match($id){
1,2,3 => 1,
4,5,6 => 2,
7,8,9 => 3,
10,11,12 => 4,
13,14,15 => 5
};
}catch(UnhandledMatchError){
$this->result('参数错误',400);
}
2 . Nullsafe运算符 ?->
$attr = $obj !== null ? $obj->attr :‘’;
上边表达式可以替换成下面
$attr = $obj?->attr;
3. 函数
1. 查找字符串$haystack中是否包含$needle
str_contains ( string $haystack , string $needle ) : bool
2.字符串以$needle开头、以$needle结尾
str_starts_with ( string $haystack , string $needle ) : bool
str_ends_with ( string $haystack , string $needle ) : bool