Detailed description of var_dump () function in php _ PHP Tutorial

Source: Internet
Author: User
Detailed description of var_dump () function in php. This article provides a comprehensive introduction to the usage of var_dump () functions in php. For more information, see. Var_dump () voidvar_dump (mixedexpression [, mixedexpression [,...]) This article provides a comprehensive introduction to the usage of var_dump () functions in php. for your reference, see.

Var_dump ()

Void var_dump (mixed expression [, mixed expression [,...])

The var_dump () method is to judge the type and length of a variable and output the value of the variable. if the variable has a value, it is the value of the variable and returns the data type.
This function displays the structure information about one or more expressions, including the expression type and value. The array recursively expands the value and displays its structure through indentation.


Example 1

The code is as follows:

$ A = "alsdflasdf; ";
$ B = var_dump ($ );
Echo"
";
// Var_dump ($ c );
$ D = var_dump ($ c );
Echo"
";
Echo $;
Echo"
";
Echo $ B;
Echo"
";
Output:
String (12) "alsdflasdf;"
NULL
Alsdflasdf;

Example 2

1. var_dump () example

The code is as follows:

     $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] => string (1) "c "}}

*/

$ B = 3.1; $ c = TRUE; var_dump ($ B, $ c );

/* Output: float (3.1) bool (true)

*/?>

Var_export and serialize cache arrays

$ Str = serialize ($ arr); the converted strings are different. The first is the array prototype, and the second is the serialized format. The first method is to add Tags form an available array prototype. for calls, you can directly return this array without Conversion. but for the second type, you need to use the unserialize function to list it in reverse order. For the first statement, one more step is required. Let's talk about it with data:

The code is as follows:

Set_time_limit (50); $ a = array (1, 2, 3); $ B = array ('a' => 1, 'B' => 2, 'C' => 3); $ c = array ('a' => array (1, 2, 3), 'B' => array (4, 5, 6 ));

$ Time1 = microtime (true );

$ Times = 1000000; #10 w

For ($ I = 1; $ I <= $ times; $ I ++) {$ A = var_export ($ a, true );}

$ Time2 = microtime (true );

For ($ I = 1; $ I <= $ times; $ I ++) {$ B = var_export ($ B, true );}

$ Time3 = microtime (true );

For ($ I = 1; $ I <= $ times; $ I ++) {$ C = var_export ($ c, true );}

$ Time4 = microtime (true );

For ($ I = 1; $ I <= $ times; $ I ++) {$ X = serialize ($ );}

$ Time5 = microtime (true );

For ($ I = 1; $ I <= $ times; $ I ++) {$ Y = serialize ($ B );}

$ Time6 = microtime (true );

For ($ I = 1; $ I <= $ times; $ I ++) {$ Z = serialize ($ c );}

$ Time7 = microtime (true );

For ($ I = 1; $ I <= $ times; $ I ++) {$ O = unserialize ($ X );}

$ Time8 = microtime (true );

For ($ I = 1; $ I <= $ times; $ I ++) {$ P = unserialize ($ Y );}

$ Time9 = microtime (true );

For ($ I = 1; $ I <= $ times; $ I ++) {$ Q = unserialize ($ Z) ;}$ time10 = microtime (true );

$ Var_export_time ['A'] = $ time2-$ time1; $ var_export_time ['B'] = $ time3-$ time2; $ var_export_time ['c'] = $ time4-$ time3;

$ Serialize_time ['A'] = $ time5-$ time4; $ serialize_time ['B'] = $ time6-$ time5; $ serialize_time ['c'] = $ time7-$ time6;

$ Unserialize_time ['A'] = $ time8-$ time7; $ unserialize_time ['B'] = $ time9-$ time8; $ unserialize_time ['c'] = $ time10-$ time9; 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 data above shows that the performance of the var_export function is twice worse than that of the serialize function, and the unserialize time must be about the same as that of the serialize function. the time when serialize is added is about the same as when var_export is used.


For details about the usage of lift () functions, refer. 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.