Difference Between Echo And Print in Php with Example

Echo And Print in Php with Example

In PHP there are two basic ways to get output: ECHO and PRINT.

In this tutorial we use echo (and 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 in Php with Example

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 echo statement can be used with or without parentheses: echo or echo().

The output of the above PHP code will look something like this: Hello Digital Technology Hub

 Display HTML Code

The output of the above PHP code will look something like this:

This is a Digital Technology Hub.

This is heading with style.

The following example will show you how to display HTML code using the echo statement:

 

The output of the above PHP code will look something like this:

 The Print statement can be used with or without parentheses: Print or Print ().You can also use the print statement (an alternative to echo) to display output to the browser.

Both echo and print statement works exactly the same way except that the print statement can only output one string, and always returns 1. That’s why the echo statement considered marginally faster than the print statement since it doesn’t return any value.

Thanks for reading my article aboutDifference Between Echo And Print in Php with Example”. If you like this article do me favor by sharing it with your friends.

Digital Technology Hub