PHP我正在检查存储在我的变量中的值是否等于0或1.
根据值,我想在我的html表单中显示一些文本。
我在$ details ['status']里面的值是字符串类型的0。
当我print_r()在if-else结构之外时,结果为0.
但是,如果我在if语句中使用了print_r(),那我什么都不会回来。
我做了的var_dump()和所述值是字符串类型如果HTML中的语句为
<form class="form-horizontal" action="/MVC/teacher/becomeTeacher" method="post">
<?php print_r($details['status'])?> <!-- Gives me 0 -->
<?php if($details['status'] === 1): ?>
This will show if the status value is 1.
<? elseif ($details['status'] === 0): ?>
Otherwise this will show.
<?php endif; ?>
</form>
EDIT
我试图多个选项的。
选项A - 两个if语句都执行。
<?php if($details['status'] == 0): ?>
This will show if the expression is true.
<? elseif ($details['status'] == 1): ?>
Otherwise this will show.
<?php endif; ?>
选项B - 两个if语句执行
<?php if($details['status'] === '0'): ?>
This will show if the expression is true.
<? elseif ($details['status'] === '1'): ?>
Otherwise this will show.
<?php endif; ?>
我找到了解决办法,但我觉得它多余
<?php if($details['status'] === '1'): ?>
This will show if the expression is true.
<?php endif; ?>
<?php if($details['status'] === '0'): ?>
Otherwise this will show.
<?php endif; ?>
什么是'$细节[ '状态']'型?字符串还是Int? –
你有没有试过简单的'=='比较? –
您是否确定这是一个int'var_dump'或者'print_r'的结果? – chris85