[Php] echo and var_dump

Source: Internet
Author: User
[Php] the core functions of echo and var_dump echo are the same as those of var_dump. they are all "output variable values". however, echo tends to be a product, debugs and programmers are more suitable to use var_dump to output variables. when debugging, say goodbye to the echo that is difficult to use!

Echo can only output the value of a variable. var_dump can output the value and type of a variable at the same time.

If no processing is performed, an array cannot be directly output in php. a for loop is required. If an array is output using echo, php reports an error, however, var_dump is fine, and the output is perfect without any processing.

The other is the output of class variables. If no processing is done, echo will also report an error, and var_dump can easily output.

The code is as follows:

 "; // Gorgeous separator, ignore var_dump ($ I); echo"
"; // Gorgeous separator, please ignore // For array output $ arr = array (, 3); echo $ arr; // output warning echo"
"; // Gorgeous Separator. ignore var_dump ($ arr); echo"
"; // Gorgeous separator, please ignore // For class Output class Test {public $ I =" I "; public $ j =" j ";} $ test = new Test (); var_dump ($ test); echo"
"; // Gorgeous separator, ignore echo $ test; // output the echo Error"
"; // Gorgeous separator, please ignore?>
The output result is as follows:


You can see that var_dump is very good for the output of variables, arrays, and classes. through var_dump, you can easily observe the value of variables, arrays, and classes. Echo reports an error as a dog. of course, we do not want software product customers to see var_dump output information in the output of common web pages, so echo is the most basic thing.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.