Home > Backend Development > PHP Tutorial > Detailed explanation of var_dump() function in php_PHP tutorial

Detailed explanation of var_dump() function in php_PHP tutorial

WBOY
Release: 2016-07-20 10:59:03
Original
1478 people have browsed it

本文章给大家全面的介绍一下关于php中var_dump()函数用法详解,大家可参考参考。  

var_dump()

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

var_dump()方法是判断一个变量的类型与长度,并输出变量的数值,如果变量有值输的是变量的值并回返数据类型.
此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值。数组将递归展开值,通过缩进显示其结构。


例1

 代码如下 复制代码

$a = "alsdflasdf;a";
$b = var_dump($a);
echo "
";
//var_dump($c);
$d=var_dump($c);
echo "
";
echo $a;
echo "
";
echo $b;
echo "
";
输出:
string(12) "alsdflasdf;a"
NULL
alsdflasdf;a

例2

1. var_dump() 示例

 代码如下 复制代码

 

<!--?php<br /-->	$a = array (1, 2, array ("a", "b", "c"));
var_dump ($a);
Copy after login

 

/* 输出: 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);

/* 输出: float(3.1) bool(true)

*/ ?>

 

 

var_export and serialize do array caching

$str = serialize($arr); The strings converted by these two mechanisms are different. The first is the prototype mode of the array, and the second is the serialized form. The first type is saved in the file as long as the tag is added, and a usable array prototype is formed. For the call, no conversion is required, and the array can be returned directly, but the second type needs to be used again. The unserialize function deserializes it. For the first one, there is one more step. Let’s talk with data:

The code is as follows Copy code
 代码如下 复制代码

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; #10w

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($a); }

$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)

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; #10w

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($a); }

$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.81780314 4455 [c] => 3.7992968559265)
Explained by the above data: The performance of the var_export function is twice as bad as the performance of the serialize function, and the unserialize time also takes about the same time as serialize. The time of serialize plus unserialize is almost the same as the time of using var_export. http://www.bkjia.com/PHPjc/445634.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445634.htmlTechArticleThis article will give you a comprehensive introduction to the usage of the var_dump() function in PHP. You can refer to it. var_dump() void var_dump ( mixed expression [, mixed expression [, ...]] )...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template