Back to Top

Difference between echo and print in PHP

echo and print in PHP

Is there any difference between print and echo in PHP? Here is one quick article about Basic PHP and it is about to differentiate echo and print.The two most basic construct to display output are echo and print.It can confuse user because its a basic construct of PHP language and also functions in PHP. We can use both print and echo either with parentheses or without parentheses.

NOTE: To call the function, we always have to use the name of the function first followed by a parenthesized list of the arguments to the function.

What is Echo?

The simplest usage of the echo is to display a string as an argument.

Example

Or we can use:

Both of the above statements will display string without the quote signs.You can also pass multiple arguments without parenthesis of echo with comma separated values like

But we can pass the multiple arguments in echo with the parenthesize. however, the echo will not accept multiple arguments:

What is print?

The print is mostly similar to echo with two important differences:

  1. print can accept only single argument.
  2. print returns a value which represents whether the print statement succeeded or not.

The value returned by print will be 1 if the print was successful and 0 if unsuccessful.

The print is mostly similar to echo with two important differences:

Mostly echo and print both are used with string arguments but we can use any type of argument and it will not cause any error.

Example

The second line will not convert argument into the string.If you use var_dump you will get a second line as a number, not a string. so we can use print and echo both to display numbers as well as string arguments.

In addition,generally we are using two printing functions print_r() and var_dump() for debugging.The main purpose of both the functions are to help to visualize what’s going on with compound data structures like arrays.

Finally, at the end Share in comment section if you want to know more about print and echo statement.

Comments (3)

  1. I do trust all the ideas you have introduced in your post. They’re very convincing and will certainly work. Still, the posts are very quick for newbies. May just you please extend them a little from subsequent time? Thank you for the post.

  2. Ya good site mate

  3. Itˇs in reality a nice and useful piece of info. Iˇm happy that you simply shared this useful info with us. Please stay us up to date like this. Thank you for sharing.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to display ADMIN Toolbar in UI

Posted on 6 years ago

Bhumi

How to use Replace function in MySQL

Posted on 6 years ago

Bhumi

Overview of ECMAScript 6 new Features

Posted on 7 months ago

Bhumi