php empty和isset区别
文章描述:
php判断变量是否为空,如果不为空设置默认值
isset()
判断变量是否被赋值
$user['username'] = 'admin';
//echo $user['username'];
$username = isset($user['username']) ? $user['username'] : "默认用户名";
echo $username;
empty()
判断一个已经被赋值的变量是否为空
$user['username'] = 'admin';
$username = !empty($user['username']) ? $user['username'] :'默认';
echo $username;
发布时间:2023/10/28
发表评论