Total members 11890 |It is currently Thu Apr 25, 2024 6:22 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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




Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

The same ??

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

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:

_________________
Coding my life with Java, PHP, JavaScript, and Python


Author:
Newbie
User avatar Posts: 39
Have thanks: 15 time

For this message the author isuru has received gratitude : DrRakha

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.


Author:
Newbie
User avatar Posts: 9
Have thanks: 1 time

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.


Author:
Newbie
User avatar Posts: 12
Have thanks: 1 time

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.


Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time

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


Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time

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


Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time
Post new topic Reply to topic  [ 8 posts ] 

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



Topic Tags

PHP Basics






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com