Echo (), print (), Print_r (), Var_dump difference?

Source: Internet
Author: User

Common output statements

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

<Html><Head><Title></Title></Head><Body><FormAction= "formprocess1.php"Method= "POST"><Table><Tr><Td>name</Td><Td><InputType= "Text"Name= "Name"Id= "Name"/></Td></Tr><Tr><Tdcolspan= "2"Style= "Text-aligh:center"><InputType= "Submit" Name= "Submit"  value< Span style= "color: #0000ff;" >= "Submit" /> </> </tr> </table> Span style= "color: #0000ff;" ></form> </< Span style= "color: #800000;" >body></html< Span style= "color: #0000ff;" >>                 

formprocess1.php

<Html><Head><Title></Title><Body><?PHP echo ' ?><pre> <strong>degug:</ strong> <?php Echo ($_post); ?> </pre> </body> Span style= "color: #0000ff;" ></head></< Span style= "color: #800000;" >html>           

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.

Echo (), print (), Print_r (), Var_dump difference?

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.