The difference between the output string in PHP (Echo,print,printf,print_r and Var_dump) "reprint"

Source: Internet
Author: User

Echo ()
Multiple values can be output at one time, and multiple values are separated by commas. Echo is a language structure (language construct), not a real function and therefore cannot be used as part of an expression.

Print ()
The function print () prints a value (its arguments) and returns True if the string is successfully displayed, otherwise false.

Print_r ()
You can simply print the string and the number, and the array is displayed with the enclosed key and the list of merits, starting with an array. However, the result of Print_r () output Boolean and null is meaningless because it is all printed "\ n". Therefore, using the Var_dump () function is more suitable for debugging.

Var_dump ()
Determine the type and length of a variable, and output the value of the variable if the variable has a value for the variable and the return data type. This function displays structure information about one or more expressions, including the type and value of the expression. The array recursively expands the value and displays its structure by indentation.

Look at the code below form1.php

formprocess1.php

The result of using the echo output is:

Hello!
Degug: Array

The result of using the print () output is:

Hello!
Degug: Array

The result of using the Print_r () output is:

Hello!
Degug: Array (    [name] +     [Submit] = submit)

The result of using the Var_dump () output is:

Hello!
degug:Array (2) {  ["name"]=>  string (0) ""  ["Submit"]=>  string (6) "Submit"}

We can see that the var_dump () output is the most informative, so use this function frequently to debug the program.

Tyler Ning
Source: http://www.cnblogs.com/tylerdonet/
This article is copyright to the author and the blog Garden, welcome reprint, but without the consent of the author must retain this paragraph of the statement, and in the article page obvious location to the original connection, if there is a problem, you can contact me through the following email address [email protected] , thank you very much.

The difference between the output string in PHP (Echo,print,printf,print_r and Var_dump) "reprint"

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.