Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在带有条件的php中包含php文件_Php - Fatal编程技术网

如何在带有条件的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)