The difference between print (), Print_r (), Echo () in PHP is detailed _php

Source: Internet
Author: User
Keywords Php print () Print_r () Echo ()
ECHO is a PHP statement, print and Print_r are functions, the statement does not return a value, the function can have a return value (even if it is not used)

Print () prints only the values of a simple type variable (such as int,string)

Print_r () can print out values for complex type variables (such as arrays, objects)

echo outputs one or more strings

Print-Output a string

Description

int print (string arg)//return value is reshape

print "Hello friend";

You can do the following

The code is as follows:


$name =print "Nihao \ n";
$STR = ' Test print value is $name. ';
Eval_r ("\ $print =\" $str \ "; " );
Echo $print;

Print_r-Print easy-to-understand information about variables.

BOOL Print_r (mixed Expression_r [, BOOL Return])//Return value is Boolean, parameter is mix type, can be string, shape, array, object class Print_r () display easy-to-understand information about a variable. If a string, integer, or float is given, the variable value itself is printed. If an array is given, the keys and elements are displayed in a certain format. object is similar to an array.

Print_r () Moves the pointer of the array to the last edge.

You can

The code is as follows:


Print_r (str);
Print_r (int);
Print_r (array);
Print_r (obj);

You can also use Var_dump Var_export

echo--output one or more strings

Description

void Echo (String arg1 [, String ...])//return value is empty

echo "Hello", "friend";

Summarize:

The functions of Echo and print in PHP are basically the same (output), but there are subtle differences between the two. There is no return value after the echo output, but print has a return value and returns Flase when its execution fails. It can therefore be used as a normal function, such as executing the following code after the variable "value will be 1."
$r = print "Hello world";
This means that print can be used in some complex expressions, while Echo is not. However, because the Echo statement does not require any values to be returned, the Echo statement in the code is running more efficiently than the print statement.

ECHO has no return value; Print has a return value, and the return value of print is always 1.

  • Related Article

    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.