Share a self-written PHPCONFIG class. The biggest feature of this class is that it can load wireless depth configuration items, and some configuration items can also be modified during configuration use, with a depth of no more than 5 levels. /*** Config. php ** discription ** @ filenameco share a self-written php config class
The biggest feature of this class is that it can load wireless depth configuration items, and some configuration items can be modified during the configuration process, with the depth not more than 5 levels.
/*** Config. php ** discription ** @ filename config. php * @ version v1.0 * @ update 2011-8-9 * @ author randy. hong * @ contact homingway@163.com * @ package config */define ('Ds', DIRECTORY_SEPARATOR); define ('path _ config ','. '. DS. 'configs'); // config param key separatordefine ('config _ separator ','. '); class CONFIG {protected static $ _ configarray = array ();/*** get a configuration * @ param string $ key * @ return mixed */p Ublic static function get ($ key = '') {// inlegal param, return falseif (! $ Key) {return false;} // without separator in param, return the whole config fileif (strpos ($ key, CONFIG_SEPARATOR) === false) {if (! Isset (self ::$ _ configarray [$ key]) {$ pai_file = PATH_CONFIG.DS. 'config. '. $ key. '. php '; if (file_exists ($ pai_file) {self ::: _ configarray [$ key] = include_once ($ pai_file) ;}} return self :: $ _ configarray [$ key];} else {$ param = explode (CONFIG_SEPARATOR, $ key); if (! Isset (self ::$ _ configarray [$ param [0]) {$ pai_file = PATH_CONFIG.DS. 'config. '. $ param [0]. '. php '; if (file_exists ($ pai_file) {self ::: _ configarray [$ param [0] = include_once ($ pai_file); }}$ tmp_config = null; for ($ I = 1; $ I
Configuration File: configs/config. test. php
return array('test1' => array('test2' => array('test3' => array('test4' => array('test5' => 5555,),),),));
Call file
include_once('config.php');$config = CONFIG::get('test.test1');print_r($config);CONFIG::set('test.test1',222);$config = CONFIG::get('test.test1');print_r($config);The first floor of lifei6671 seems to have the same effect as the discuz configuration file!