Wednesday, 8 July 2015

PHP Echo / Print

 Difference between PHP echo() and PHP print()?
Echo and Print are almost same both are used to display the output but there is minor difference between these two is that :
  • Echo is more faster than print.
  • PHP print() has a return value , whereas PHP echo() has a void return type.
  • PHP echo() and php print() both are different. print() return value on the other hand echo() not return any value.
  • Echo is a constructor and Print is a function.
  • In PHP, echo is not a function but a language construct, whereas print is not a function but a language construct. However, it behaves like a function in that it returns a value.
  • One of the most important difference in between these : Echo can take multiple values whereas print cannot, it take only one parameter.
  • We take a example it became easy for you to understand this.
  • Firstly taking a example of  php echo in php:
<html><head>
<title> echo  program</title>
</head>
<body>
<?php
echo’cascading’,’style’,’sheet';
//one or more strings

?>
</body>
</html>
  • Output will be:
cascadingstylesheet
  •  Now we take a Example of print:
<html><head>
<title> print program</title>
</head>
<body>
<?phpprint ‘cascading’,’style’,’sheet';?>
</body>
</html>
  • Output will be:
Parse error: syntax error, unexpected ‘,’ on line number 7, because print only display one string.
  •  Now we take again print Example having one string:
<html><head>
<title>print program</title>
</head>
<body>
<?php
<>print ‘name';//one or more strings
?>
</body>
</html>
  • Output will be:

name

No comments:

Post a Comment