Php:具有一些复杂性的逻辑查询

时间:2015-01-22 15:18:44

标签: php html

我有基本知识在php中编写代码,但我陷入了逻辑过程。希望我能在这里得到一些帮助。

问题:

我想根据表现比较并宣布2名工人之间的胜利者。详情如下:

$working_first = 2;
$available_canches = 5;
$target_minutes = 40;

Worker1的详细信息

$worker1 = 2 ;
$worker1_chances_taken = 4;
$worker1_points = 80;
$worker1_minutes = 40;

Worker2的详细信息

$worker2 = 5 ;
$worker2_chances_taken = 5;
$worker2_points = 95;
$worker2_minutes = 35;

预期解决方案:

我想要运行一些程序......

  • if $working_first == $worker1 AND $target_minutes>$worker1_minutes OR $available_chances>$worker1_chances_taken
  • if $working_first != $worker1 AND $worker1_points>$worker2_points AND $target_minutes>$worker2_minutes OR $available_chances>$worker2_chances_taken

我用于输出的语法:

if (($working_first==$worker1 && ($target_minutes>$worker1_minutes || $available_chances>$worker1_chances_taken)) || ($working_first != $worker1 && $worker1_points>$worker2_points && ($target_minutes>$worker2_minutes || $available_chances>$worker2_chances_taken)) {

echo 'Process Continues';

}

else {

echo 'Process Ends';

}

我无法获得所需的输出。

请帮我搞定。

感谢。

1 个答案:

答案 0 :(得分:0)

您尚未正确关闭括号。试试这个:

if (
 (
  $working_first == $worker1
  && 
  (
   $target_minutes > $worker1_minutes 
   || 
   $available_chances > $worker1_chances_taken
  )
 ) 
 || 
 (
  $working_first != $worker1 
  && 
  $worker1_points > $worker2_points 
  && 
  (
   $target_minutes > $worker2_minutes 
   || 
   $available_chances > $worker2_chances_taken
  )
 )
) {

 echo 'Process Continues';

} else {

 echo 'Process Ends';

}