Difference between echo and print with example

This question often asked in interviews, this looks like a simple question but you know many times I failed in Interviews just because of this kind of silly questions.

So really any difference there of print and echo in PHP?

Yes, there are few worthy difference you can mention in the interviews:

1. print returns a value (the value will be 1 always), but echo won’t return anything.

For example:

The output of the above code will be 1
But for echo you cannot assign a variable, it will through a fatal error.

2. Very small speed difference between echo and print, echo works faster because it does not return value.

3. You can pass multiple parameters in echo (comma separated)but print will accept only one.

For eg:

I hope this is enough to explain to the Interviewers. Enjoy the day!

Related Posts

Leave a Reply