Differences between PHP: echo, print, print_r, sprintf, and var_dump

Source: Internet
Author: User
[Convert] the difference between PHP: echo, print, print_r, sprintf, and var_dump-echo is a command and cannot return a value. Echo can be followed by multiple parameters separated by semicolons, such as echo $ myvar1; echo1, 2, $ myvar, & lt; B & gt; bold & lt; B & gt;-print is a function. one value can be returned and only one parameter is allowed. -Pr [to] PHP: differences between echo, print, print_r, sprintf, and var_dump

-Echo
It is a command and cannot return values. Echo can be followed by multiple parameters separated by semicolons, for example:

echo $myvar1;echo 1,2,$myvar,"bold";

-Print
Yes. one value can be returned and only one parameter is allowed.

-Printf
Function to format and output the text, for example:

$name="hunte";$age=25;printf("my name is %s, age %d", $name, $age);

-Sprintf
Similar to printf, but not printed, the formatted text is returned. Others are the same as printf.

-Print_r
Print_r is usually used to print information about variables, which is usually used in debugging.

Print_r (true); // output 1print_r (false); // no output print_r (null); // no output

-Var_dump
Var_dump this function displays the structure information about one or more expressions, including the expression type and value.

Var_dump (true); // output bool (true) var_dump (false); // bool (false) var_dump (null); // bool (null)

Differences between var_dump () and print_r:
Var_dump returns the expression type and value while print_r returns only the result, which is easier to read than using var_dump in debugging code.

<PHP>

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.