包括后,foreach停止

时间:2017-09-14 18:36:16

标签: php foreach include

为什么foreach在包含(第二个)后停止?这是我的代码:

define('MONITORING_MOD', dirname(__FILE__) . '/');

$entries = scandir(MONITORING_MOD);
foreach($entries as $entry) {
    if (preg_match('%[a-zA-Z0-9_-]%', $entry)) {
        if(is_file(MONITORING_MOD . $entry) && $entry != 'init.php') {
          include_once(MONITORING_MOD . $entry);
        } else if ($entry != 'init.php') {
          $sub_entries = scandir(MONITORING_MOD . $entry);
          foreach($sub_entries as $sub_entry) {
            echo MONITORING_MOD . $entry . '/' . $sub_entry;
            if (preg_match('%[a-zA-Z0-9_-]%', $sub_entry)) {
              include(MONITORING_MOD . $entry . '/' . $sub_entry);
            }
          }
        }
    }
}

我尝试使用include_once,制作特殊功能并没有帮助。 此代码中的另一个include_once也可以完美地运行在foreach之外。

0 个答案:

没有答案
相关问题