PHP echo/print echo ' $firstname com '; When there are variables, you must use double quotes echo just faster than the print Print_r function

Source: Internet
Author: User
Tags echo command

In general, the dynamic output of HTML content in PHP is achieved through print and ECHO statements, and in practice, both print and ECHO functions are almost identical. It can be said that there is a place to use, and the other can be used. However, there is also a very important difference between the two: in the Echo function, you can output multiple strings at the same time, and in the print function you can only output one string at a time. At the same time, the Echo function does not require parentheses, so the echo function is more like a statement than a function.   Echo and print are not functions, but language constructs, so parentheses are not required. the difference between them is:

(1) echo can output multiple strings, like this:

1 echo‘a‘,‘b‘,‘c‘;

If you have to add parentheses, note that echo (' A ', ' B ', ' C ') is wrong and should be written as:

1 echo(‘a‘),(‘b‘),(‘c‘);

It does not behave like a function, so it cannot be used in the context of a function (2) print can only output a string, it can behave like a function, for example, you can use the following:

1 $ret= print‘Hello World‘;

All of it can be used in more complex expressions. Plus,Echo's efficiency is relatively fast!

The echo command is the same as the Print command, no difference
The Echo function differs from the print function.
Echo () No return value, same as echo command
Print () has a return value, success, return to 1,false, return 0.
printf () is similar to sprintf (), which is formatted output, but is output to standard output, which is output to a variable

PHP echo/print echo ' $firstname com '; When there are variables, you must use double quotes echo just faster than the print Print_r function

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