How to use the var_export function. The var_export function is used. the var_export usage method var_export () function returns the structure information about the variables passed to the function, which is similar to var_dump, the difference is the usage of the var_export function returned by var_export.
The var_export () function returns the structure information about the variables passed to the function. it is similar to var_dump (). The difference is that the returned representation is a valid PHP code. Var_export must return valid php code, that is, the code returned by var_export can be directly assigned a variable as a php code. This variable gets the same type value as var_export. Let's look at the following simple example:
Program output:
array ( 0 => 1, 1 => 2, 2 => array ( 0 => 'apple', 1 => 'banana', 2 => 'orange', ),)
Note that the above output is a valid PHP code. If var_dump () is used, the output is:
array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(3) { [0]=> string(5) "apple" [1]=> string(6) "banana" [2]=> string(6) "orange" }}
You can set the second parameter of the function to TRUE to return the expression of the variable.
Program running result:
'nowamagic'
Note:
- Var_export () keeps structured data.
- However, remember that the variable value type is already a string ($ var). you cannot retrieve the value from the array.
In the source code of PHPCMS, we can see that many configuration parameters are recorded in arrays, including their channels and contents.
function cache_write($file, $string, $type = 'array') { if(is_array($string)) { $type = strtolower($type); if($type == 'array') { $string = "
"; } elseif($type == 'constant') { $data=''; foreach($string as $key => $value) $data .= "define('".strtoupper($key)."','". addslashes($value)."');\n"; $string = "
"; } } $strlen = file_put_contents(PHPCMS_CACHEDIR.$file, $string); chmod(PHPCMS_CACHEDIR.$file, 0777); return $strlen; } Additional reading
The topic list of this article is as follows:
The var_export () function returns the structure information about the variables passed to the function. it is similar to var_dump (), but the difference is that it returns...