There is no difference in the core functions of echo and var_dump. They are both "outputting the value of the variable", but echo is biased towards products and is for customers. Debuggers and programmers are more suitable to use var_dump to output variables during debugging. , say goodbye to the hard-to-use echo!
echo can only output the value of the variable, while var_dump can output the value and type of the variable at the same time.
If you don’t do any processing, you can’t directly output an array in PHP. You need to use a for loop. If you directly use echo to output an array, PHP will report an error, but var_dump can still output it. It's perfect, no need to go through any processing.
The next thing is the output of class variables. If no processing is done, echo will also report an error, but var_dump can easily output.
An example is also used to illustrate this problem. The code is as follows:
<?php //对于普通变量的输出 $i=1; echo $i; echo "<br>";//华丽的分隔符,请忽略 var_dump($i); echo "<br>";//华丽的分隔符,请忽略 //对于数组的输出 $arr=array(1,2,3); echo $arr;//输出警告 echo "<br>";//华丽的分隔符,请忽略 var_dump($arr); echo "<br>";//华丽的分隔符,请忽略 //对于类的输出 class Test{ public $i="i"; public $j="j"; } $test = new Test(); var_dump($test); echo "<br>";//华丽的分隔符,请忽略 echo $test;//输出错误 echo "<br>";//华丽的分隔符,请忽略 ?>
You can see that var_dump has a good performance for the output of variables, arrays, and classes. You can easily use var_dump Observe the values of variables, arrays, and classes at this time. Echo reports an error as a dog. Of course, in the output of ordinary web pages, we do not want software product customers to see the information output by var_dump, so echo is still the most basic thing.
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above has introduced echo and var_dump, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.