Page 1 of 1

print echo

Posted: Sun Jul 24, 2005 9:20 am
by shiznatix
what is the difference between print and echo

Posted: Sun Jul 24, 2005 9:25 am
by John Cartwright
Straight from the manual
echo

(PHP 3, PHP 4, PHP 5 )
echo -- Output one or more strings
Description
void echo ( string arg1 [, string ...] )

Outputs all parameters.

echo() is not actually a function (it is a language construct) so you are not required to use parentheses with it. In fact, if you want to pass more than one parameter to echo, you must not enclose the parameters within parentheses.
print

(PHP 3, PHP 4, PHP 5 )
print -- Output a string
Description
int print ( string arg )

Outputs arg. Returns 1, always.

print() is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list.

Posted: Sun Jul 24, 2005 10:08 am
by wwwapu
In real life there is not much difference, which one you use but check this out:

Code: Select all

<?php
$string1="Hello ";
$string2="world";
echo $string1,$string2;
print $string1 . $string2;
?>
See the difference?