如何在带有条件的php中包含php文件
在本地主机上运行代码时,我遇到了如何在带有条件的php中包含php文件,php,Php,在本地主机上运行代码时,我遇到了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{ $o
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
,效果很好 除了明显的拼写错误(If中的大写字母I,条件末尾的逗号),您使用了错误的运算符<代码>=是赋值运算符。要检查相等性,应使用==
运算符:
if ($res == 1) {
// ---^
$open = include ("weekend.php");
}
else {
$open = include ("weekday.php");
}
纠正您的if条件。。。。。。。。。If($res=1)变为If($res=1)