【发布时间】:2013-05-27 19:09:23
【问题描述】:
我正在运行 PHP 5.3,但遇到了一个奇怪的问题。有没有人遇到过这个问题?
if(isset($_POST['favorites'])) { $fave = $_POST['favorites']; }
elseif(isset($_GET['favorites'])) { $fave = $_GET['favorites']; } else { $fave = 0; }
echo $fave; //echoes 0
if($fave=="addto"){ //This is called and looks like $fave is temporarily set to "addto"
echo $fave; //echoes 0
}
$fave 从未设置为“addto”,但 if 语句出于某种原因将其视为“addto”。任何人以前都遇到过这种情况,或者对如何使其按应有的方式工作有任何想法?
【问题讨论】:
-
数据类型比较(松散类型)与 ==
If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically.- php.net/manual/en/language.operators.comparison.php
标签: php variables if-statement variable-assignment