dsxrq28228
2012-08-25 17:44
浏览 97
已采纳

在PHP中使用布尔运算

Well, I come from compiled languages as Java and now I am trying to deal with PHP in some specific areas. Today, I have created a "test form" in order to know how to check for valid values, and now I have a little problem.

Suppose that I have multiple fields to evaluate, using a boolean variable I would like to do something like this:

//ASSUMING THAT ALL IS CORRECT
$correct =  true;

$correct &= is_ok($name);
$correct &= is_ok($last_name);
$correct &= is_ok($nickname);
$correct &= is_ok($best_friend);

if (!$correct) {
    //AT LEAST ONE FIELD IS INCOMPLETE
}
else
{
    // EVERYTHING IS OK
}

function is_ok($field){
    return !empty($field);
}

The problem that I am issuing is that &= looks like is not working correctly. Do I need to use another boolean operator?

图片转代码服务由CSDN问答提供 功能建议

好吧,我来自Java编译语言,现在我试图在某些特定领域处理PHP。 今天,我已经创建了一个“测试表单”,以便知道如何检查有效值,现在我有一点问题。

假设我有多个字段要评估,使用 一个布尔变量我想做这样的事情:

  //假设一切都是正确的
 $ correct = true; 
 
 $ correct& = is_ok  ($ name); 
 $ correct& = is_ok($ last_name); 
 $ correct& = is_ok($ nickname); 
 $ correct& = is_ok($ best_friend); 
 
if(!  $ correct){
 //至少一个字段不完整
} 
else 
 {
 //一切正常
} 
 
函数is_ok($ field){
 return!empty($ field)  ); 
} 
   
 
 

我发出的问题是& = 看起来无法正常工作。 我是否需要使用另一个布尔运算符?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题