+ -
当前位置:首页 → 问答吧 → 请教三元运算符与if判断的省略写法

请教三元运算符与if判断的省略写法

时间:2011-09-18

来源:互联网

请教:如下注册验证的简单代码,验证CAPTCHA的三元运算符语句只写出了条件,并没有“?:”,这是通用的省略写法吗?

再有下面的if语句,只写出了
if ($password  && $captcha &&
如果 $password 是 $password !='' 的省略,那 $captcha 的完整写法是什么呢?

    $password1 = (isset($_POST['password1'])) ? $_POST['password1'] : '';
    $password2 = (isset($_POST['password2'])) ? $_POST['password2'] : '';
    $password = ($password1 && $password1 == $password2) ?
        sha1($password1) : '';

    // 如果用户输入了验证码并且与session中保存的验证码一致
    $captcha = (isset($_POST['captcha']) &&
        strtoupper($_POST['captcha']) == $_SESSION['captcha']);

    // add the record if all input validates
    if ($password &&
        $captcha &&
        User::validateUsername($_POST['username']) &&
        User::validateEmailAddr($_POST['email']))
    {

[ 本帖最后由 qaz8555 于 2011-9-18 08:19 编辑 ]

作者: qaz8555   发布时间: 2011-09-18

完全不懂你的意思,贴完整代码。

作者: Frears   发布时间: 2011-09-18

热门下载

更多