包含名称在数组中的文件

时间:2016-02-24 11:17:48

标签: php include

我正在尝试将大量文件包含到我的页面中,使用数组作为文件名。

$arr=array(01,02,03,04); 
foreach ($arr as $filename) { 
  $filename="pars/".$filename.".inc"; 
  include $filename; 
}

我也试过这段代码:

$arr=array(01,02,03,04);
foreach ("pars/".$arr.".inc" as $filename) { include $filename; }

现在我使用更简单的组合来包含目录中的所有文件:

foreach (glob("pars/*.inc") as $filename) { include $filename; }

但我需要制作包括可选项。我的错在哪里?或者有更简单的方法吗?

2 个答案:

答案 0 :(得分:0)

你的数组必须是字符串:

$arr=array('01','02','03','04');

答案 1 :(得分:0)

我想你可能想采取不同的方法。

PHP确实提供了自动加载类。

看看这两个链接: http://php.net/manual/en/language.oop5.autoload.php http://php.net/manual/en/function.spl-autoload-register.php

相关问题