+91 9952732367

PHP echo and print statement

5. PHP echo and print statement

echo() and print() are not functions but language constructs in PHP. They are both used to output strings and there are very minor differences between echo and print in PHP.

echo() statement:

  • echo can take more than one parameter when used without parentheses. The syntax is echo expression [, expression[,expression] … ]. Note that echo ($arg1,$arg2) is invalid.
  • echo does not return any value.

Syntax:

  • void echo ( string $arg1 [, string $… ] )

print() statement:

  • print only takes one parameter.
  • print always returns 1 (integer)
  • int print ( string $arg )
  • In PHP, print is not a really function but a language construct. However, it behaves like a function in that it returns a value.

Syntax:

  • int print ( string $arg )
<?php
echo "String1", "String2", " String3";
$str="S3learn.com";
print "Learn PHP at $str";
?>
Copyright © s3learn.com