Difference between echo and print statements
October 9, 2016 Comments 0 412 Views

Difference between echo and print statements

In PHP there are two basic ways to get your output : echo and print statements.

We will show the difference between echo and print statements with a working example. This examples will contain all information about echo and print statements.

echo and print statements are more or less the same. They both used to output data to the screen in your php code.

The differences are small like echo has no return value while print has a return value of 1 so it can be used in expressions. Secondly echo can take multiple parameters (although such usage is rare) while print can take one argument. If we talk about performance you can say echo is marginally faster than print.

PHP echo Statement :

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

Example 1 :

 

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

Example 2 :

PHP print Statement :

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

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

Example 1 :

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

Example 2 :

Next Remove category & tag base from WordPress url

About author

Rio
Rio 37 posts

Expert web developer working in PHP, Wordpress, Joomla, Magento, Javascript etc.

You might also like

PHP function to sort array alphabetically or numerically in ascending or descending order.

In this article we will walk through with example on how the PHP array sort functions works to sort the arrays key and values in alphabetically/numerically or ascending/descending order. Sort

ZIP Files & Folder using Simple PHP Code

Using PHP you can Zip Files and Folders with a simple php code, which will provide you with the functionality to create zip automatically without manual efforts. Simple PHP code to

Error Handling in PHP 7

The next feature we going to cover are the changes to Error Handling. Handling fatal errors in the past has been next to impossible in PHP. A fatal error would

How to detect website is access from Mobile using PHP.

Todays trend shows that maximum number of website access using mobile is increased. People are using smart phone to access the mobile instead of their desktop OR laptop. Because mobile

PHP 7 Using New Operators

PHP 7 also brings us some new operators. Let’s just cut the talk and directly check how PHP 7 Using New Operators. Spaceship Operator : The spaceship operator, or Combined Comparison

Secure directory by allowing access to IP address & Deny all using htaccess

Your website may have folders which you want to keep secure access using URL. For example Admin area you want to keep secure to access using particular IP address and

Avoid things In Smarter PHP 7

mysql_ Functions : The mysql extension (and the mysql_* functions) have been deprecated since PHP 5.5. For a direct migration, you can use the mysqli extension and the mysqli_* functions

Store passwords securely in PHP to prevent password hacking

While creating an application using PHP there are maximum chances that you have login for which you have to store user data which also contain passwords for login. We will

Post data to third party site using PHP CURL

PHP supports CURL library which allows you to connect and communicate to many different types of servers with many different types of protocols and supports the http, https, ftp etc.