Print V/S echo

print vs echo

Bonus Point - print_r

echo and print are more or less the same. They are both used to output data to the screen. The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.

About print_r :-

Definition and Usage The print_r() function prints the information about a variable in a more human-readable way.

<?php $ret = print("hello world");
print "Return by print function = ".$ret;
//$ret_echo = echo "hello "; not possible
echo "No return in echo";
$var = print_r("hello",true); echo $var;
$a = array("red", "green", "blue"); print_r($a); ?>

Result above code -

hello world
Return by print function = 1
No return in echo
hello
Array ( [0] => red [1] => green [2] => blue )