简体   繁体   English

PHP中的if elseif语句

[英]if elseif statement in PHP

Both if and elseif statement are working at the same time. if和elseif语句同时工作。

  while($answerResult = mysql_fetch_assoc($answers))
  {
    if($reportResult != 0 && $this->CheckAnswer($questionId,$answerResult['id'],$reportResult))
    {
       echo '<input type="radio" name="question['.$questionId.']" value="'.$answerResult['id'].'" checked/>'.$answerResult['name'].'aaa&nbsp;&nbsp';
    }
    elseif($sampleResult != 0 && $this->CheckAnswer($questionId,$answerResult['id'],$sampleResult))
    {
       echo '<input type="radio" name="question['.$questionId.']" value="'.$answerResult['id'].'" checked/>'.$answerResult['name'].'hee&nbsp;&nbsp';
    }
    else
    {
       echo '<input type="radio" name="question['.$questionId.']" value="'.$answerResult['id'].'" />'.$answerResult['name'].'&nbsp;&nbsp';
    }
  }

I'm trying to do if my first statement is true then don't look other conditions but if my first condition is false then check elseif condition. 我正在尝试执行以下操作:如果我的第一个语句为true,则不查找其他条件,但是如果我的第一个条件为false,则检查elseif条件。

However, my elseif condition is working even though first if condition is true. 但是,即使条件为true,我的elseif条件仍然有效。

I put 'hee' and 'aaa' at the end of the 'echos' to see which one is printing. 我在“ echos”的末尾加上“ hee”和“ aaa”,以查看正在打印的是哪一个。

The result: 结果:

First, if statement is working and printing with 'aaa' then looking at the elseif statement and checked this and print 'hee'. 首先,如果语句正在工作并以'aaa'打印,则查看elseif语句并检查并打印'hee'。

So, I don't know what i am missing and can't find any solution, Is there any suggestion? 因此,我不知道自己缺少什么,找不到任何解决方案,是否有任何建议?

The if , elseif , and else in one statement are exclusive, so this shouldn't happen. 一个语句中的ifelseifelse是互斥的,因此不应发生这种情况。

The whole statement is in a while loop ... are you sure it's not the if being executed in the first iteration and the elseif being executed in the second iteration? 整个语句处于while循环中...您确定不是在第一次迭代中执行ifelseif在第二次迭代中执行吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM