如何检查字段是否为空?

use*_*374 3 html php redirect

所以我在PHP中使用了这个代码,并且由于某些我不知道的原因它不能正常工作:

if(!empty($ccle))
{
    header("Location: http://google.com");
}

else
{
    header("Location: http://yahoo.com");
}
Run Code Online (Sandbox Code Playgroud)

我想要的是:如果"ccle"字段为空,那么转到google.com或者如果"ccle"字段不为空(哪里是值),那么转到yahoo.com

如何做到这一点?

doi*_*tin 9

你需要切换它们......

if(!empty($ccle))
{
    // Go to Yahoo if $ccle is NOT empty
    header("Location: http://yahoo.com");
}
else
{
    // Else, go to Google
    header("Location: http://google.com");
}
Run Code Online (Sandbox Code Playgroud)

只是详细说明.你的if发言是......

if($ccle IS NOT empty)
Run Code Online (Sandbox Code Playgroud)

PHP中的感叹号是逻辑运算符.

  • 好抓!:). (2认同)