Difference between echo and print in php

When you are working with the php then you get the question that what is difference between echo and print, below is the clerification

echo and print both are same but there is difference in that which is you should know when you working with php web-site. echo and print both are php language constructs and used to display the string.
1) when you called echo then the return type is void for that while in the print its return value, by default print return 1.
2) echo is faster then the print, it means the execution of echo statement take less time then the print.
3) you can pass multiple parameter in the echo statement while in the print you can pass only single parameter.

Most of the PHP developers use Echo over Print even they do not know the difference but once you know the difference, always use echo and avoid to use print for better performance of the web-application.

print_r () is a PHP function and it is used to return an array in a human readable form. It is simply written as print_r ($your_array).

Almost all php developer use the print_r function to display the values of the php array variable and its good habit because using the print_r function you can easily debugging array and onjects, if you need more clear result of the array elements then you can wrap the output in the <pre></pre> tags.

For Example.

$a = array(‘PHP’,’MySQL’,’Javascript’);


Output is
Array([0] => PHP [1]=> MySQL [2]=> Javascript)

but if you use below code
echo “<pre>”; print_r(a); echo “</pre>”;

Output is
[0] => PHP
[1]=> MySQL
[2]=> Javascript

You can decide yourself that which is better to understand if there is huge number of elements in the array.