这种方式加载配置文件是一种好的方式

时间:2023-02-02 11:24:11

<!-- One situation where returning a value from a script and using it could be considered a good use is config(配置) files. Zend Framework 2 promotes(促进) this structure(结构) for this purpose, and it works pretty well.

Example config file:

这种方式加载配置文件是一种好的方式,并能把配置文件加入环境 $GLOBALS['config']数组中在全局调用的时候是非常方便的  -->

<?php
return [
  'site' => 123,
  'settings' => 'asd'
];

$GLOBALS['variable'] = something;

<?php
$config = (require 'config.php');
// Or
$config = array_merge(require 'config/local.php', require 'config/application.php');