Home > Backend Development > PHP Tutorial > A brief analysis of the differences between echo(), print(), print_r(), return_PHP Tutorial

A brief analysis of the differences between echo(), print(), print_r(), return_PHP Tutorial

WBOY
Release: 2016-07-13 17:17:36
Original
797 people have browsed it

What are the differences between echo(), print(), print_r(), and return in PHP?

There are often many novices and friends who don’t use print() well who cannot answer this question and therefore fail the interview.

So what is the difference between them? Let’s take a look below

Answer:
echo is a PHP statement, print and print_r are functions, statements have no return value, and functions can have return values ​​(even if they are useless)
print () can only print out the value of simple type variables (such as int, string)
print_r () can print out the value of complex type variables (such as array, object)
return statement exits from the current function and exits from that The function returns a value.

echo outputs one or more strings
echo — outputs one or more strings
Descrīption
void echo ( string arg1 [, string ...] ) / /The return value is empty
echo "Hello", "Friend";

print – Output a string
Descrīption
int print ( string arg )//The return value is an integer
print “Hello friend”;

You can perform the following operations
$name=print “nihao /n”;
$str = ‘test print value is $name.’;
eval(“/$print=/”$str /”;”);
echo $print;

print_r — Print easy-to-understand information about a variable.
bool print_r (mixed expression [, bool return] ) //The return value is Boolean, the parameter is of mix type, which can be string, integer, array, object class print_r() displays about a variable of easy-to-understand information. If a string, integer, or float is given, the variable value itself is printed. If an array is given, the keys and elements will be displayed in a certain format. object is similar to an array.

Note: print_r() will move the array pointer to the end

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621717.htmlTechArticleWhat are the differences between echo(), print(), print_r(), and return in PHP? There are often many novices and friends who don’t use print() well who cannot answer this question and therefore fail the interview. So what are the differences between them...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template