include 与 include_once 除了加载次数的区别还有是否能获取文件return 数据的区别
先准备两个文件, route.php 我们要获取这个文件中return 的数组; init.php 是我们获取的代码文件。
route.php
<?php
return array (
'article/:id\d/:cid\d' => 'portal/article/index',
'list/:id\d' => 'portal/list/index',
'product/:id\d/:term_id\d' => 'portal/product/index',
'news' => 'portal/list/index?id=8',
'page/:id\d' => 'portal/page/index',
'study' => 'portal/index/study',
);
init.php
<?php
$get = include "route.php";
var_dump($get);
$get2 = include_once "route.php";
var_dump($get2);
打印结果:
macbook-pro-xiao:demo chenxiao$ php init.php
array(6) {
["article/:id\d/:cid\d"]=>
string(20) "portal/article/index"
["list/:id\d"]=>
string(17) "portal/list/index"
["product/:id\d/:term_id\d"]=>
string(20) "portal/product/index"
["news"]=>
string(22) "portal/list/index?id=8"
["page/:id\d"]=>
string(17) "portal/page/index"
["study"]=>
string(18) "portal/index/study"
}
bool(true)
总结:
- include 可以获取到 route.php 中 return 的数组
- include_once 只能获取到true