Differences between echo, print, and print_r in php

Source: Internet
Author: User
Differences between echo, print, and print_r in php: information can be output, but each of them has its own characteristics: & nbsp; number of type output variables output variable type return & #20540; the speed echo language structure is one or more simple type variables. for example, int and string do not have the fastest print language structure. a simple type variable, such as echo, print, and print_r differences in I php

Overview:

All three of them can output information, but each has its own characteristics:

  Type Number of output variables Output variable type Return value Speed
Echo Language structure One or more Simple type variables, such as int and string None Fastest
Print Language structure One Simple type variables, such as int and string Int Fast
Print_r Function One Complex types, such as arrays and objects Bool Slow

Echo is not a function, but a php statement. it can use commas to output multiple variables without returning values, and the speed is also the fastest.

 
Print and echo are basically the same, but print can only output one variable and return values. if the output is successful, 1 is returned.

 
Print_r is a function that prints easy-to-understand information about variables. If the parameter is string, integer, or float, the variable value is printed. If the parameter is array, the key and element are displayed in a certain format. Objects are similar to arrays.

Print_r has two parameters: the first parameter is the variable, and the second parameter can be set to true. if it is set to true, the variable to be printed is returned; otherwise, the boolean value is returned.

 "Xyw", "2" => "Eliot", "3" => "blog"); print_r ($ arr ); // output array $ return = print_r ($ arr); // return value: 1 echo $ return; // output 1 $ return = print_r ($ arr, true ); // returns the array echo $ return; // output array?>
Output:

Array
(
[1] => xyw
[2] => Eliot
[3] => blog
)

This article is original Eliot, reprinted please indicate the source: http://blog.csdn.net/xyw_blog/article/details/13743341

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.