Is the isset in the code {code...} always false? Because the array $ configs at the beginning is empty. The main reason is not to understand static $ configsarray (); after $ configs, isn't it an empty array. Sorry, don't step on me any more.
public static function load_config($file, $key = '', $default = '', $reload = false) { static $configs = array(); if (!$reload && isset($configs[$file])) { if (empty($key)) { return $configs[$file]; } elseif (isset($configs[$file][$key])) { return $configs[$file][$key]; } else { return $default; } }
Is isset always false in this code? Because the array $ configs at the beginning is empty. The main reason is not to understand static $ configs = array (); after $ configs, isn't it an empty array. Sorry, don't step on me any more.
Reply content:
public static function load_config($file, $key = '', $default = '', $reload = false) { static $configs = array(); if (!$reload && isset($configs[$file])) { if (empty($key)) { return $configs[$file]; } elseif (isset($configs[$file][$key])) { return $configs[$file][$key]; } else { return $default; } }
Is isset always false in this code? Because the array $ configs at the beginning is empty. The main reason is not to understand static $ configs = array (); after $ configs, isn't it an empty array. Sorry, don't step on me any more.
Local static variables retain the value of the previous execution and will not be reinitialized. Your code is not fully intercepted. The $ configs value assignment statement follows. you can simply addprint_f($configs);Let's take a look at the $ configs value every time load_config is called.
The purpose of this operation is to cache the $ configs value during the current execution process to avoid the judgment and include operations of the file_exists consumed in the future.
For details, see TIPI: static variables.
static $configs = array();
Static variables