Switch to full style
Dynamic open source server-side web development
Post a reply

Difference between PHP echo() and PHP print()?

Fri Dec 03, 2010 2:27 am

What's the difference between PHP echo() and PHP print() ?



Re: What's the difference between PHP echo() and PHP print()?

Fri Dec 03, 2010 12:31 pm

The same ??

Re: What's the difference between PHP echo() and PHP print()?

Fri Dec 03, 2010 7:41 pm

Code:
<?php
     
print "Hello World! <br />";
     echo 
"Hello World! <br />";
     
// The above outputs the text "Hello World!" on two separate lines.
     // Notice they are identical in output!

     
print ("Hello World! <br />");
     echo (
"Hello World! <br />");
     
// The above are just the same, with parenthesis.
     // Notice both can act like functions, but note they actually aren't.
?>


In all actuality, Echo and Print differ based on how they are structured. Print returns a value much like a normal function would. But despite common belief, Print is not a function, as we can see by the fact that it doesn’t require parenthesis to work (Not to be confused with Printf). Print and Echo are actually both called language constructs, although this isn’t to say that we can’t make Print act like a function.

PHP Echo Vs Print: Which Is Faster?

Echo is faster than print.

Print can be used as part of complex constructs, such as
($b) ? print “True” : print “False”; // or echo ($b ? “true” : “false”);
Also, if you want to use error output (@print”Test”;)
Print is easy because almost every language use it. but most php developers use echo because it is faster and it is sounds cool!

Use what you prefer and easy for you! :sohappy:

Re: Difference between PHP echo() and PHP print()?

Tue Oct 16, 2012 11:12 am

PHP Print and Echo both output data to the screen in a same pattern but PHP Echo and PHP Print differ based on how they are structured.

Re: Difference between PHP echo() and PHP print()?

Tue Oct 30, 2012 12:47 pm

In PHP, echo is not a function but a language construct. In PHP, print is not a really function but a language construct. However, it behaves like a function in that it returns a value.

Re: Difference between PHP echo() and PHP print()?

Tue Apr 02, 2013 5:22 am

The echo() function is slightly faster than print(). With echo you can send a string of text.
The print() function outputs one or more strings.

Re: Difference between PHP echo() and PHP print()?

Sat Apr 27, 2013 12:57 pm

PHP print() has a return value , whereas PHP echo() has a void return type, echo can take multiple parameters.

Re: Difference between PHP echo() and PHP print()?

Tue May 07, 2013 1:49 pm

PHP echo() and PHP print() both are different. print() return value and echo() not return any value. echo is a constructor and print is a function

For Example:
echo "String 1";
print("String 1");
echo print("String 1");
returns boolean 0 or 1

Post a reply
  Related Posts  to : Difference between PHP echo() and PHP print()?
 PHP echo command     -  
 echo client using Sockets     -  
 Echo multiline string     -  
 echo command to output HTML     -  
 Help for Print using php     -  
 Print the ASCII Set     -  
 print element in 2d matrix     -  
 How to print a webcam picture in Jsp     -  
 Print all MySQL status value     -  
 Get union of two arrays set and print it     -  

Topic Tags

PHP Basics