私の変数に格納されている値が0または1であるかどうかを確認しています。
HTMLのフォームの中にテキストを表示します。
$ details ['status']の中にある値は、文字列型の0です。
if-else構造体の外側でprint_r()を実行すると、結果は0になります。
if print_r()if文の中では何も返されません。
Iはのvar_dump()および値は、私は複数のオプションを試みHTML内のPHP ifステートメント
型ストリング
<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 - 両方の文が
<?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? –
シンプルな '=='比較を試しましたか? –
これは 'var_dump'または' print_r'の結果でintであると判断しましたか? – chris85