A detailed description of the Var_dump () function in PHP _php tutorial

Source: Internet
Author: User
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]=> string (1) "B" [2]=&G T 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.848389863 9679) 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 similar.


http://www.bkjia.com/PHPjc/445634.html www.bkjia.com true http://www.bkjia.com/PHPjc/445634.html techarticle 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 [, ...]]) ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.