PHP中??的相关理解
$post = [
'page' => 10,
'b' => 200
];
$page = $post['page'] ?? 1;
// 等价于
$page = isset($post['page']) ? $post['page'] :1;
$page = $post['page'] ?: 1;
// 等价于
$page = $post['page'] ? $post['page'] :1;
// 这个是上传文件的方法 失败返回false
$res = $this->uploadfile();
$img_path = $res ?: '';
实际不上也就这两个常用:
$a??1;
$a?:1;
转自:https://learnku.com/articles/60741