function C ($name =null, $value =null, $default =null) { static $_config = Array (); Get all if (empty ($name)) {return $_config when no parameters ; } Precedence execution set GET or assign if (is_string ($name)) { if (!strpos ($name, '. ')) { $name = Strtolower ($name); if (Is_null ($value)) return isset ($_config[$name]) $_config[$name]: $default; $_config[$name] = $value; return; } Two-dimensional array settings and get support $name = explode ('. ', $name); $name [0] = strtolower ($name [0]); if (Is_null ($value)) return isset ($_config[$name [0]][$name [1]])? $_config[$name [0]][$name [1]]: $default; $_config[$name [0]][$name [1]] = $value; return; } Bulk set if (Is_array ($name)) { $_config = Array_merge ($_config, Array_change_key_case ($name)); return; } return null; Avoid illegal parameters}
This is the function defined in the function.php inside the thinkphp.
Detailed
The functions of this function are:
1, get the $_config array, which holds the configuration information (static variables are initialized only once, the function is completed, the value will not disappear)
Print_r (C ()); This will get all the configuration information that has been read or set
2. Read the value of the configuration
echo C (' key '), Echo C (' Key.subkey ');//Read the two-dimensional array, the corresponding configuration file structure is return array (' key ' =>array (' subkey ', ' value ')
3, dynamic Add configuration
C (' key ', ' value '); C (' Key.subkey ', ' value ');
Key points of C function implementation:
1, Static $_config = Array (); Set the $_config to a static variable so that it can store the value
2, the configuration file of the wording.
return $arr = Array ( ' key1 ' = ' value '; ' Key2 ' =>array (' subkey ', ' value '), */* Note the beginning of return, when include this file, returns the return value of this return */
Inspired:
Development projects can be used for reference, the function of the system configuration is still very useful.
thinkphp function Learning (3): C-Function explanation