Echo (), print (), print_r (), var_dump ()

Source: Internet
Author: User
Echo (), print (), print_r (), var_dump (), echo (), print (), print_r (), var_dump (), 1. echo outputs one or more strings. 2. print is the same as echo, and the speed is slower than echo. 3. print_r prints easy-to-understand information about variables, such as echo (), print (), print_r (), and var_dump ().
Differences between echo (), print (), print_r (), and var_dump ()

------ Solution --------------------
1. echo
Output one or more strings.
2. print
Like echo, the speed is slower than echo.
3. print_r
Print easy-to-understand information about Variables. if string, integer, or float is provided, the variable value itself is printed. If array is provided, keys and elements are displayed in a certain format. Objects are similar to arrays. Remember, print_r () will move the array pointer to the last edge. Use reset () to bring the pointer back to the beginning.
4. var_dump
This function displays the structure information about one or more expressions, including the expression type and value. The array recursively expands the value and displays its structure through indentation.
5. 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.
------ Solution --------------------
-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 1
Print_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.
------ Solution --------------------
① Echo: COMMAND. return value is not allowed. Echo can be followed by multiple parameters separated by semicolons (;) and connected by dots, for example:

Echo $ myvar1;
Echo 1, 2, $ myvar ," Bold";

② Print: Function. one value can be returned and only one parameter is allowed.

③ Printf: Function. format the text and output it, for example:

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

%-Percentage sign returned
% B-binary number
% C-characters based on ASCII values
% D-signed decimal number
% E-resumable counting (for example, 1.5e + 3)
% U-unsigned decimal number
% F-floating point number (local settings aware)
% F-floating point number (not local settings aware)
% O-octal values
% S-string
% X-hexadecimal (lowercase letter)
% X-hexadecimal (uppercase letters)

④ Sprintf: Similar to printf, but not printed, it returns formatted text. Others are the same as printf.

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

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

⑥ 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)

7. 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.

------ Solution --------------------
The general difference is as mentioned above
In addition, correcting print () is not a function. although it can contain parentheses and return values
Http://docs.php.net/manual/zh/function.print.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.