为了账号安全,请及时绑定邮箱和手机立即绑定

小白,请教各位大佬!php 引入 .php?求解答!

小白,请教各位大佬!php 引入 .php?求解答!

吃鸡游戏 2019-06-09 10:51:28
现在一般我引入就是这样require_once'/configurations/environment.php';只是这样当configurations多了很多个php时,就必须一个一个打上去引入require_once'/configurations/environment.php';require_once'/configurations/environment2.php';require_once'/configurations/environment3.php';require_once'/configurations/environment4.php';require_once'/configurations/environment5.php';.....这样是否太麻烦有无我只要引入「configurations」文件夹,等同于引入了里面全部的.php程式呢?
查看完整描述

2 回答

?
呼啦一阵风

TA贡献1802条经验 获得超6个赞

functionrequireDir($dir){
$handle=opendir($dir);
while(false!==($file=readdir($handle))){
if($file!='.'&&$file!='..'){
$filepath=$dir.'/'.$file;
if(filetype($filepath)=='dir'){
requireDir($filepath);
}else{
require_once$filepath;
}
}
}
}
requireDir('./php_fun');
test();
自己写个方法就行了,不过最好还是加上命名空间。不说可以解决方法名冲突,还能让自己看起来很专业哈哈哈
                            
查看完整回答
反对 回复 2019-06-09
?
汪汪一只猫

TA贡献1898条经验 获得超8个赞

尽量避免使用*_once方法。
$files=glob('/path/*.php');
foreach($filesas$file){
require$file;
}
                            
查看完整回答
反对 回复 2019-06-09
  • 2 回答
  • 0 关注
  • 237 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号