A detailed description of the Var_dump () function in PHP
Source: Time: 2013-09-05 18:33:53 read:460047
Share to:
[Guide] This article gives you a comprehensive introduction to the PHP var_dump () function usage in detail, we can refer to the reference. Var_dump () void var_dump (mixed expression [, mixed expression [,]]) the Var_dump () method is to determine the type of a variable with a long
This article gives you a comprehensive introduction about PHP var_dump () function usage in detail, you can refer to the reference.
Var_dump ()
void Var_dump (mixed expression [, mixed expression [, ...]])
The Var_dump () method is to determine the type and length of a variable, and to output the value of a variable, if the variable has a value to lose is the values of the variable and returns the data type.
This function displays structure information about one or more expressions, including the type and value of the expression. The array recursively expands the value and displays its structure by indentation.
Example 1
The code is as follows |
Copy Code |
$a = "Alsdflasdf;a"; $b = Var_dump ($a); echo " "; Var_dump ($c); $d =var_dump ($c); echo " "; echo $a; echo " "; Echo $b; echo " "; Output: String ("Alsdflasdf;a") Null Alsdflasdf;a |
Example 2
1. Var_dump () example
The code is as follows |
Copy Code |
$a = Array (1, 2, Array ("A", "B", "C")); Var_dump ($a); /* Output: Array (3) {[0]=> int (1) [1]=> int (2) [2]=> Array (3) {[0]=> string (1) "A" [1]=& Gt String (1) "B" [2]=> string (1) "C"}} */ $b = 3.1; $c = TRUE; Var_dump ($b, $c); /* Output: Float (3.1) bool (TRUE) */?> |
Var_export and serialize do array caching
$str = serialize ($arr); The two mechanisms convert the string to be different, the first is the prototype pattern of the array, and the second is the serialized form. The first type of deposit in the file as long as the tag, in the form of a usable array prototype, for the call, do not have to convert, directly return the array can be, but the second, you need to use the Unserialize function to deserialize once again. For the first one, one more step. Let's speak with the data:
The code is as follows |
Copy Code |
Set_time_limit (50); $a = Array (+/-); $b = Array (' A ' =>1, ' B ' =>2, ' C ' =>3); $c = Array (' A ' =>array (), ' B ' =>array (4,5,6)); $time 1 = microtime (true); $times = 1000000; #10w for ($i =1; $i <= $times; $i + +) {$A = Var_export ($a, true);} $time 2 = Microtime (true); for ($i =1; $i <= $times; $i + +) {$B = Var_export ($b, True);} $time 3 = Microtime (true); for ($i =1; $i <= $times; $i + +) {$C = Var_export ($c, True);} $time 4 = Microtime (true); for ($i =1; $i <= $times; $i + +) {$X = serialize ($a);} $time 5 = Microtime (true); for ($i =1; $i <= $times; $i + +) {$Y = serialize ($b);} $time 6 = Microtime (true); for ($i =1; $i <= $times; $i + +) {$Z = serialize ($c);} $time 7 = Microtime (true); for ($i =1; $i <= $times; $i + +) {$O = Unserialize ($X);} $time 8 = Microtime (true); for ($i =1; $i <= $times; $i + +) {$P = Unserialize ($Y);} $time 9 = Microtime (true); for ($i =1; $i <= $times; $i + +) {$Q = Unserialize ($Z);} $time = Microtime (true); $var _export_time[' a '] = $time 2-$time 1; $var _export_time[' b '] = $time 3-$time 2; $var _export_time[' c '] = $time 4-$time 3; $serialize _time[' a '] = $time 5-$time 4; $serialize _time[' b '] = $time 6-$time 5; $serialize _time[' c '] = $time 7-$time 6; $unserialize _time[' a '] = $time 8-$time 7; $unserialize _time[' b '] = $time 9-$time 8; $unserialize _time[' c '] = $time 10-$time 9; Print_r ($var _export_time); Print_r ($serialize _time); Print_r ($unserialize _time);?> Output:array ([a] + 3.3401498794556 [b] = 5.1394801139832 [c] = 8. 8483898639679) Array ([a] = 1.6063709259033 [b] = 1.7033960819244 [c] = = 3.4534389972687) array ([a] = 1.6037359237671 [b] = 1.817803144455 [c] + 3.7992968559265) |
The above data show: Var_export function performance than the performance of serialize function is one times, and unserialize time also need and serialize almost time, serialize plus unserialize time, and Var_ Export time is almost
Var_dump ()