5. PHP Echo and Print Statements
PHP Syntax, Variables and PHP Echo/Print

5. PHP Echo and Print Statements

With PHP, there are two basic ways to get output: echo and print.

In this tutorial we use echo or print in almost every example. So, this chapter contains a little more info about those two output statements.

PHP echo and print Statements

echo and print are more or less the same. They are both used to output data to the screen.

The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.

The PHP echo Statement

The echo statement can be used with or without parentheses: echo or echo().

Display Text

The following example shows how to output text with the echo command (notice that the text can contain HTML markup):

Display Variables

The following example shows how to output text and variables with the echo statement:

The PHP print Statement

The print statement can be used with or without parentheses: print or print().

Recommended  2. How to Install Apache, MySQL and PHP in Ubuntu 18.04 LTS Part 1

Display Text

The following example shows how to output text with the print command (notice that the text can contain HTML markup):

Display Variables

The following example shows how to output text and variables with the print statement:

 

[Total: 1    Average: 5/5]

Detri Amelia Chandra

Hello, I introduce myself Detri Amelia Chandra. Some of my expertise is in System Analysis, Database Design, Artificial Neural Networks and a little in Programming. Check out my thoughts about the world on my blog. I updated this blog a bit rarely, so please keep visit my blog here often ...

Leave a Reply

Close Menu