PHP中的If语句快把我逼疯了


If statement in PHP driving me up the wall

好吧,我自学了PHP,做了大约40个小时的小项目,我想我没有搞不懂一个简单的IF语句,但是....下面的两个回显显示了正确的内容(密码和密码长度)。

但是,带有"ARGH"的回显和studentnotexist函数被调用了!我也不知道为什么。当然很简单。

echo $password;
echo strlen($password);
if (strlen($password < 2)) {
    echo "********************* ARGH ************************";
    studentnotexist();
    session_destroy();
    die();
}
else 
//Begin IF blocks that test various conditions for user name and password
if ($password != $passwordentered) { //if password is wrong
    badpassword();
    die();
} 

您正在检查"$password <$2"不是"$password"的长度。

观察差异:

if (strlen($password < 2)) {

if (strlen($password) < 2) {

看括号在哪里

你想要第二个

注意括号的关闭位置:

if (strlen($password) < 2)