在本地主机上运行代码时,include
命令遇到问题。
这是我的代码:
<?php
$res = 2; // this also can be change to any number. it is based on user input, but for simply the problem i make it to be set manually
If ($res =1,){
$open = include ("weekend.php");
}
else{
$open = include ("weekday.php");
}
echo $open;
?>
我希望输出为weekday.php
,但输出为weekend.php
。
如果我使用$res = 1
,效果很好。
答案 0 :(得分:2)
除了明显的拼写错误(If
中的大写字母I,条件末尾的逗号)之外,您还使用了错误的运算符。 =
是赋值运算符。为了检查是否相等,您应该使用==
运算符:
if ($res == 1) {
// ---^
$open = include ("weekend.php");
}
else {
$open = include ("weekday.php");
}