The Var_export () function returns the structure information about the variable passed to the function, similar to Var_dump (), unlike the PHP code whose returned representation is legitimate. Var_export must return a valid PHP code, that is, the code returned by Var_export can be directly assigned to a variable as PHP code. And this variable gets the same value as the Var_export type. Let's look at a simple example:
<?php$arr = Array (1, 2, Array ("Apple", "banana", "orange")); Var_export ($arr); ? >
Program output:
Array ( 0 = 1, 1 = 2, 2 = = Array ( 0 = ' Apple ', 1 = ' banana ', 2 = ' Oran GE ', ),)
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 return the representation of a variable by setting the second argument of the function to TRUE.
<?php$v = ' nowamagic '; $rs = Var_export ($v, TRUE); Echo $rs;? >
Program Run Result:
' Nowamagic '
Note two points:
- Var_export () retains the structured form of storing data.
- But in particular, remember that the type of the variable value at this point is already a string ($var), and it is no longer possible to take the value out of the array.
In the Phpcms source code, you can see that many of the configuration parameters are recorded in an array, including their channels, content, and so on.
function Cache_write ($file, $string, $type = ' array ') { if (Is_array ($string)) { $type = Strtolower ($ type); if ($type = = ' array ') { $string = "<?php\n return". Var_export ($string, TRUE). "; N?> "; } ElseIf ($type = = ' constant ') { $data = '; foreach ($string as $key = = $value) $data. = "define ('". Strtoupper ($key). "', '". Addslashes ($value). "'); \ n "; $string = "<?php\n". $data. " \n?> "; } } $strlen = File_put_contents (phpcms_cachedir. $file, $string); chmod (Phpcms_cachedir. $file, 0777); return $strlen; }
Extended Reading
The list of topics for this article is as follows:
- PHP function Completion: GET_MAGIC_QUOTES_GPC ()
- PHP function Completion: error_reporting ()
- PHP function Completion: Preg_match ()
- PHP function Completion: UrlEncode ()
- PHP function Completion: Array_multisort ()
- PHP function Completion: Array_splice ()
- PHP function Completion: isset ()
- PHP function Completion: getenv ()
- PHP function Completion: header ()
- PHP function Completion: mysql_num_rows ()
- PHP function Completion: List ()
- PHP function Completion: mysql_query ()
- PHP function Completion: mysql_fetch_array ()
- PHP function Completion: Number_format ()
- PHP function Completion: Explode ()
- PHP function Completion: Call_user_func ()
- PHP function Completion: Imagecopyresamples ()
- PHP function Completion: Import_request_variables ()
- PHP function Completion: Parse_url ()
- PHP function Completion: Remove HTML tag strip_tags ()
- PHP function Completion: output array structure and content var_dump ()
- PHP function Completion: Var_export ()
- PHP function Completion: Determine whether the variable is a digital is_numeric ()
- PHP function Completion: Session_name ()
- PHP function Completion: session_id ()
- PHP function Completion: NL2BR () and nl2p () function
- PHP function Completion: Shuffle () take an array of random elements
- PHP function Completion: http_build_query () constructs URL string
- PHP function Completion: stream_context_create () Analog post/get
How to use the Var_export function