Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP回显中包含if语句?_Php_Html_If Statement_Echo - Fatal编程技术网

如何在PHP回显中包含if语句?

如何在PHP回显中包含if语句?,php,html,if-statement,echo,Php,Html,If Statement,Echo,但我不能让它这样工作 这就是我在if语句中想要的 ' . if() {} . ' if($student_answer_per_question====''学生回答.''){ 问题未尝试正确答案为“。$numberofanswersperquestion[0]['Answer\u name']” } 我希望我已经详细解释了这个问题,我感谢你们的帮助。谢谢在echo语句之前创建一个变量,例如$statement,并使用PHP速记If/Else,类似这样 if($student_answer_p

但我不能让它这样工作

这就是我在if语句中想要的

' . if() {} . '
if($student_answer_per_question====''学生回答.''){
问题未尝试
正确答案为“
。$numberofanswersperquestion[0]['Answer\u name']” }

我希望我已经详细解释了这个问题,我感谢你们的帮助。谢谢

在echo语句之前创建一个变量,例如$statement,并使用PHP速记If/Else,类似这样

if($student_answer_per_question === '' || '') {
 <tr>
    <td style="text-align: left;" width="100%" class="warning"><em>Question Not attempted</em><br><strong>Correct Answer is</strong><br>' . $numberofanswersperquestion[0]['answer_name'] . '</td>
</tr>
}
现在,您只需在echo语句中打印$语句,如下所示

$statement = ($student_answer_per_question == '')? "Option 1" : "Option 2";

您可以临时定义一个变量来存储输出

echo "blah blah $statement blah blah";
$output=
问题”。($i+1)。”
' . $问题和答案[$i]['question\u name']
';
如果(条件)
{
$output.='
问题未尝试
正确答案为“
。$numberofanswersperquestion[0]['Answer\u name']” '; } $output.=' ';
如果($student_answer_per_question===''你可以拆分回音语句
){
''
所以这就是它当前的样子,如果语句现在工作正常,但else语句在做了一些更改后,由于某些原因没有被调用,那么它当前就是这样,您是否知道,为什么else没有被调用?if语句现在工作,但else echo没有被调用谢谢我修复了它,它是if语句,应该是这样的if($student\u answer\u per\u question='')
$statement = ($student_answer_per_question == '')? "Option 1" : "Option 2";
echo "blah blah $statement blah blah";
$output = '<table class="table table-bordered table-condensed table-datatable table-hover">
                <tbody>

                    <tr>
                        <td style="text-align: left;" width="100%"><strong>Question '. ($i+1) .'</strong></td> 
                    </tr>
                    <tr>
                        <td style="text-align: left;" width="100%">' . $question_and_answers[$i]['question_name'] .'</td>
                    </tr>';
if(condition)
{
$output .= '             <tr>
                        <td style="text-align: left;" width="100%" class="warning"><em>Question Not attempted</em><br><strong>Correct Answer is</strong><br>' . $numberofanswersperquestion[0]['answer_name'] . '</td>
                    </tr>';
}
$output .=              '<tr>
                        <td style="height: 5px;" width="100%">&nbsp;</td>
                    </tr>

                    <tr>
                    <td style="height: 5px;" width="100%">&nbsp;</td>
                    </tr>

                </tbody>
                </table>';