我在while循环中有一个变量,即$confirm
这个变量是动态的,可以是任何不同值的列表。
我想在循环外部使用此变量来检查它是否等于辅助变量
<?php
$confirm = "";
while ($row_tutorunit = $tutorunit->fetch(PDO::FETCH_ASSOC)){
$confirm .= $row_tutorunit["code"];
}
?>
用法;
<?php if ($confirm !== "$anothervariable"); { echo 'style="display:none;"'; } ?>
因为我正在使用它,它似乎无法正常工作
答案 0 :(得分:1)
if ($confirm !== $anotherVariable); { echo 'test'; }
// I think your problem is here^
基本上,分散分号的作用是将if
与应附加到其上的括号中的代码分开。实际上你在告诉PHP
if ($confirm !== $anotherVariable) {
; // Do nothing
}
echo 'test'; // Always
旁注,(假设$anothervariable
是一个字符串)"$anothervariable"
与$anothervariable
完全相同。报价是多余的。但'$anothervariable'
与$anothervariable
相同,因为variable parsing适用于双引号字符串,但不适用于单引号字符串。