Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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 If语句多条件检查_Php_Arrays - Fatal编程技术网

Php If语句多条件检查

Php If语句多条件检查,php,arrays,Php,Arrays,您能帮我解决一下覆盖$tpl变量的问题吗?它只保留嵌套在foreach中的if循环中的最后一个foreach迭代数据。如果我删除嵌套的If循环,则每个循环只保留一个,则整个电视节目将列在第页上。我的目标是通过选择树输入类型=提交中的一个,按天显示电视节目。代码分为两个文件,xml2array.php和tv_schedule.php。谢谢,这是事先准备好的 下面是tv_schedule.php <!DOCTYPE html> <html> <head>&

您能帮我解决一下覆盖$tpl变量的问题吗?它只保留嵌套在foreach中的if循环中的最后一个foreach迭代数据。如果我删除嵌套的If循环,则每个循环只保留一个,则整个电视节目将列在第页上。我的目标是通过选择树输入类型=提交中的一个,按天显示电视节目。代码分为两个文件,xml2array.php和tv_schedule.php。谢谢,这是事先准备好的

下面是tv_schedule.php

<!DOCTYPE html>
<html>
    <head></head>
    <body>
        <form id="select" action="" method="get" >
            <input type="submit" name="program" value="today" />
            <input type="submit" name="program" value="tomorrow" />
            <input type="submit" name="program" value="afterTomorrow" />
        </form>

        <table id="program" class="table tablesorter">
            <thead>
                <tr>
                    <th>beginning</th>
                    <th>end</th>
                    <th>programme</th>
                </tr>
            </thead>
        <tbody>
        <?php
        include_once('xml2array.php');
        $today = date('l');
        $tomorrow = date('l', strtotime("+1 day"));
        $afterTomorrow = date('l', strtotime("+2 day"));

        if(isset($_GET['program'])) {
            $select=$_GET['program'];
            if($select == 'Today' OR 'today') {
                $select = $today;
            }
            if($select == 'Tomorrow' OR 'tomorrow') {
                $select = $tomorrow;
            }
            if($select == 'AfterTomorrow' OR 'afterTomorrow') {
                $select = $afterTomorrow;
            }               
            foreach($programXml['programme'] AS $schedule) {
                //critical if loop
                if(date('l', strtotime($schedule['start'])) == $select) {
                    $tpl = "<tr>";
                    $tpl .= "<td>". date('H:i', strtotime($schedule['start']))."</td>";
                    $tpl .= "<td>". date('H:i', strtotime($schedule['stop']))."</td>";
                    $tpl .= "<td>".$schedule['content']['title'][0]['content']."</td>";
                    $tpl .= "</tr>";
                    echo $tpl;
                }// end if
            } // end foreach
        } //end if(isset($_POST['program']))

        ?>
        </tbody>
    </table>
</body>

编辑第一个代码段xml2array.php工作正常,第二个代码tv_schedule.php,ifdate'l',strottime$schedule['start']==$select{…}是主要问题。很抱歉造成误解。

那么您是说if语句if中的代码不是循环,顺便说一句,是不是没有执行?那可能是因为它检查的条件是假的

原因可能在循环上方的代码中。这种情况是错误的:

if($select == 'Today' OR 'today') {
    $select = $today;
}
可能是:

if ($select == 'Today' or $select == 'today') {
    $select = $today;
}

这段代码中的其他类似条件也是如此。此错误导致$select的值与预期值不同。顺便说一句,你可以通过一些穷人的调试很容易地发现这一点,也就是说,通过var_转储你在if条件下比较的值。

第一块代码甚至没有变量$tpl!请参见编辑。谢谢,第一个区块仍然没有可变的$tpl。我的观点是,第一块似乎与问题无关,顺便说一下,这也不清楚。非常感谢!这正是我要找的。