Php Learning Log (3)-echo & amp; print, php Learning Log-echo

Source: Internet
Author: User
Tags parse error

Php Learning Log (3)-echo & print, php Learning Log-echo

In php, there are two methods to output the result: echo and print. The following compares the two methods.

Differences between echo and print:

  Echo Print
Continuous output string Continuous output of multiple strings Only one string can be output.
Return Value None Return 1
Usage Echo or echo () Print or print ()

(1) echo can output multiple consecutive strings, and print can only output one string:

Instance 1:

<? Php/* echo can output multiple consecutive strings, and print can only output one string */echo "echo outputs one string:"; echo "hello, world "; // echo outputs a string echo "<br/>"; echo "echo outputs multiple strings:"; echo "hello, world", "hello, php", "hello, python "; // echo outputs multiple strings echo" <br/> "; print" print outputs a string: "; print" hello, world "; // print outputs a string print "<br/>";/* start-[print outputs multiple strings consecutively]-start */
Print "print Output multiple strings:"; print "hello, world", "hello, php", "hello, python"; // print Output multiple strings, error prompt: parse error: syntax error, unexpected ', 'in C: \ Users \ 13842 \ PhpstormProjects \ test \ print & echo. php on line 14/* end-[print multiple consecutive strings]-end */print "<br/>";?>

The code that shields print from outputting multiple strings consecutively. The result is as follows:

If you do not block the code that outputs multiple strings consecutively by print, an error occurs (syntax error ):

(2) No return value for echo. print always returns 1.

<? Php/* print returns 1, and echo does not return the value */$ print_value = print "hello, world <br/>"; // result: hello, worldprint "returns $ print_value "; // result: the returned value is 1 $ echo_value = echo "hello, world <br/>"; // syntax error?>

(3) There is no difference between the output mode with and without brackets. I will not explain it here.

 

 

Technorati labels: php, echo, print

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.