Possible Duplicate:
Reference: Comparing PHP's print and echo
Is there any major and fundamental difference between these two functions in PHP?
To add to the answers above, while print can only take one parameter, it will allow for concatenation of multiple values, ie:
$count = 5;
print "This is " . $count . " values in " . $count/5 . " parameter";
This is 5 values in 1 parameter
I think print()
is slower than echo
.
I like to use print()
only for situations like:
echo 'Doing some stuff... ';
foo() and print("ok.\n") or print("error: " . getError() . ".\n");
They are:
As the PHP.net manual suggests, take a read of this discussion.
One major difference is that echo
can take multiple parameters to output. E.g.:
echo 'foo', 'bar'; // Concatenates the 2 strings
print('foo', 'bar'); // Fatal error
If you're looking to evaluate the outcome of an output statement (as below) use print
. If not, use echo
.
$res = print('test');
var_dump($res); //bool(true)
As the PHP.net manual suggests, take a read of this discussion.
One major difference is that echo
can take multiple parameters to output. E.g.:
echo 'foo', 'bar'; // Concatenates the 2 strings
print('foo', 'bar'); // Fatal error
If you're looking to evaluate the outcome of an output statement (as below) use print
. If not, use echo
.
$res = print('test');
var_dump($res); //bool(true)
They are:
To add to the answers above, while print can only take one parameter, it will allow for concatenation of multiple values, ie:
$count = 5;
print "This is " . $count . " values in " . $count/5 . " parameter";
This is 5 values in 1 parameter
As the PHP.net manual suggests, take a read of this discussion.
One major difference is that echo
can take multiple parameters to output. E.g.:
echo 'foo', 'bar'; // Concatenates the 2 strings
print('foo', 'bar'); // Fatal error
If you're looking to evaluate the outcome of an output statement (as below) use print
. If not, use echo
.
$res = print('test');
var_dump($res); //bool(true)
They are:
To add to the answers above, while print can only take one parameter, it will allow for concatenation of multiple values, ie:
$count = 5;
print "This is " . $count . " values in " . $count/5 . " parameter";
This is 5 values in 1 parameter
They are:
I think print()
is slower than echo
.
I like to use print()
only for situations like:
echo 'Doing some stuff... ';
foo() and print("ok.\n") or print("error: " . getError() . ".\n");
To add to the answers above, while print can only take one parameter, it will allow for concatenation of multiple values, ie:
$count = 5;
print "This is " . $count . " values in " . $count/5 . " parameter";
This is 5 values in 1 parameter
As the PHP.net manual suggests, take a read of this discussion.
One major difference is that echo
can take multiple parameters to output. E.g.:
echo 'foo', 'bar'; // Concatenates the 2 strings
print('foo', 'bar'); // Fatal error
If you're looking to evaluate the outcome of an output statement (as below) use print
. If not, use echo
.
$res = print('test');
var_dump($res); //bool(true)
Source: Stackoverflow.com