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.

Share:
Share on Facebook0Share on LinkedIn0Tweet about this on TwitterShare on Google+0Buffer this pageDigg thisShare on Reddit1

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 *

Most Popular Posts

How to use IndexedDB in HTML5

Posted on 2 years ago

Bhumi

How to create Custom regions in Drupal

Posted on 4 years ago

Bhumi

How to Lock File in PHP

Posted on 5 years ago

Bhumi

Facade implementation in Laravel

Updated 1 month ago

Bhumi

MySQL coalesce() function

Updated 18 years ago

Bhumi

How to use JavaScript Promise API?

Updated 18 years ago

Bhumi

What are Lambdas and Closures in PHP?

Updated 18 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 2 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 3 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 4 years ago

Bhumi