php函数var_dump,var_export,print_r的用法区别

发布时间:2020-08-12编辑:脚本学堂
本文介绍下,php中有关var_dump,var_export,print_r三个函数的区别,有需要的朋友,参考下吧。

通过例子,来看下三者的区别,用得最多的是print_r,其中var_dump和var_export比较少用,大家注意观察例子,以理解其中的区别。
例子:

<?php
/**
* php函数 var_dump var_export print_r区别
* edit www.jb200.com
*/
$a = array(1,1,32,322,3433,array(32,232,23232));  
$b = 1234;  
$c = "alsdfl;asdf";  
$d = 'a';  
$e = fopen("slsl.txt", "r");  
var_dump($a);  
echo "<br>";  
var_dump($b);  
echo "<br>";  
var_dump($c);  
echo "<br>";  
var_dump($d);  
echo "<br>";  
var_dump($e);  
echo "<br>";  
echo "<br>";  
echo "<br>";  
echo "<br>";  
var_export($a);  
echo "<br>";  
var_export($b);  
echo "<br>";  
var_export($c);  
echo "<br>";  
var_export($d);  
echo "<br>";  
var_export($e);  
echo "<br>";  
echo "<br>";  
echo "<br>";  
echo "<br>";  
print_r($a);  
echo "<br>";  
print_r($b);  
echo "<br>";  
print_r($c);  
echo "<br>";  
print_r($d);  
echo "<br>";  
print_r($e);  
echo "<br>";  
?>

输出:
 

复制代码 代码示例:

Warning: fopen(slsl.txt) [function.fopen]: failed to open stream: No such file or directory in E:mywwwyangtestbase1.php on line 6 
array(6) { [0]=> int(1) [1]=> int(1) [2]=> int(32) [3]=> int(322) [4]=> int(3433) [5]=> array(3) { [0]=> int(32) [1]=> int(232) [2]=> int(23232) } } 
int(1234) 
string(11) "alsdfl;asdf" 
string(1) "a" 
bool(false)

array ( 0 => 1, 1 => 1, 2 => 32, 3 => 322, 4 => 3433, 5 => array ( 0 => 32, 1 => 232, 2 => 23232, ), ) 
1234 
'alsdfl;asdf' 
'a' 
false 
 
Array ( [0] => 1 [1] => 1 [2] => 32 [3] => 322 [4] => 3433 [5] => Array ( [0] => 32 [1] => 232 [2] => 23232 ) ) 
1234 
alsdfl;asdf 
a

注意以上的输出,相信大家可以理解函数var_dump,var_export,print_r的区别了。
注意,最后一个不是贴出来,而是它本来就没有显示什么。
希望对大家有所帮助。