Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   What the different between print and echo (https://www.warriorforum.com/programming/235420-what-different-between-print-echo.html)

keyplay 12th July 2010 08:35 PM

What the different between print and echo
 
Hi old warrior member, What is difference between print and echo

ereadergold 12th July 2010 10:38 PM

Re: What the different between print and echo
 
Who are you calling "old"????

I assume you are speaking about PHP here, as many other languages use similar statements.

Technically echo is a bit faster than print, although we are probably talking nanoseconds here. Print also has a return value (i.e true or false), where as echo doesn't. However echo can accept multiple statements but print can't (i.e echo "The first", "the second";).

For all practical purposes use the one that makes you happy! I guess echo has one less character to type!

Bill

omonoiavas 13th July 2010 12:42 AM

Re: What the different between print and echo
 
Not much difference between print and echo.
The main differnce is that echo can take multiple expressions and its a bit faster than print

godwinsam 13th July 2010 05:27 AM

Re: What the different between print and echo
 
print does the same thing as echo except echo is a language construct and not a real function so it's syntax is different.

echo is a statement
while print is a function
we can't print whole array by using echo or print. For this we have to use the print_r function

jaratvit 13th July 2010 06:03 AM

Re: What the different between print and echo
 
A lot of people seem to prefer echo because it runs a little faster (very likely an insignificant amount of time will be gained).

There are a few situations in more complicated code where print is preferred because it can return a true/false where echo does not.

Very few people care about these technical differences and use them interchangeably.

Luxmo 3rd August 2010 11:45 AM

Re: What the different between print and echo
 
Personally, I use echo for generic printing to the document..specially when there is a lot of printing to be done. I only use the print function when there is further formatting or processing needed...like making sure something was printed using the bool return from the print function or formatting strings (like currency formats). Echo is faster than print and there is a noticeable speed difference when printing large strings.

To sum it up:
Use echo when printing anything.
Only use print when you need to print something in a special way or for bool testing.

<My two pennies>

ginny.smith73 4th August 2010 04:08 AM

Re: What the different between print and echo
 
echo can take multiple expressions + bit faster than print

rockmartinn24 4th September 2010 08:23 AM

Re: What the different between print and echo
 
The different between print and echo :

- Echo works faster than print()
- Echo and print are language construct
- Echo is not suitable for conditional construct
- Print is suitable for conditional construct
- Print process is slower than echo
- Print returns an integer values
- Echo does not returns any values

abhishekcis 16th February 2011 04:50 AM

Re: What the different between print and echo
 
Yes not much difference between print and echo.
Only syntactically echo is different with print

tirupati 16th February 2011 05:26 AM

Re: What the different between print and echo
 
Print : Prints the Line with formatted output
Echo : Just print and goes to next line

sixpack01 21st March 2011 06:22 PM

Re: What the different between print and echo
 
The difference between print() & echo()?

1. Echo() can take multiple expression
eg: Echo 'sundar','MCA'; // sundarMCA

2. Print() cannot take multiple expression
eg print 'sundar','MCA'; // Parse Error

3. Echo() doesn`t return any values.

4.print() return values. ;)

gtk29 21st March 2011 07:04 PM

Re: What the different between print and echo
 
Basic difference is that echo is not a function like print(). As such echo runs faster than print().

joshepmacarona 29th March 2011 12:40 PM

Re: What the different between print and echo
 
Prints the Line with formatted output. Echo is just print and goes to next line. Echo is not best for conditionally construct. Print is best for conditionally construct.

esoomllub 29th March 2011 05:50 PM

Re: What the different between print and echo
 
The funny thing to me is that even though I know they are pretty close to the same, I find myself constantly changing prints to echos when I take over code from someone else. I realize that it is a waste of time, but still can not find the willpower to stop myself. Argh.

yourmobisite 31st March 2011 03:47 AM

Re: What the different between print and echo
 
Some people seem to prefer echo because it runs a little faster.There are a few situations in more complicated code where print is preferred because it can return a true/false where echo does not.

Steve Wells 1st April 2011 02:06 AM

Re: What the different between print and echo
 

Print:
a process for reproducing text and image, typically with ink on paper using a printing press. It is often carried out as a large-scale industrial process, and is an essential part of publishing and transaction printing

Echo: Repetition of a sound by reflection of sound waves from a surface

:)

hhunt 1st April 2011 05:34 AM

Re: What the different between print and echo
 
Quote:

Originally Posted by Steve Wells (Post 3630693)

Print:
a process for reproducing text and image, typically with ink on paper using a printing press. It is often carried out as a large-scale industrial process, and is an essential part of publishing and transaction printing

Echo: Repetition of a sound by reflection of sound waves from a surface

:)

You may have misunderstood the question - the print and echo in this context relate to programming languages; rather than the real world interpretation of it.

hireava 1st April 2011 06:56 AM

Re: What the different between print and echo
 
Main difference between echo() and print() is that echo is just an statement not a function and doesn't return's value or it just prints a value whereas print() is an function which prints a value and also it returns value.

alexacc 6th April 2011 12:35 AM

Re: What the different between print and echo
 
Lagest difference is: Print is suitable for conditional construct - but echo - not

Steve Wells 11th April 2011 02:23 PM

Re: What the different between print and echo
 
Quote:

Originally Posted by hhunt (Post 3631458)
You may have misunderstood the question - the print and echo in this context relate to programming languages; rather than the real world interpretation of it.

Naay, just having fun....

kitchensimply 12th April 2011 07:15 AM

Re: What the different between print and echo
 
echo has the slight performance advantage because it doesn't have a return value. They both have the same functions but have different procedures that result to the same output.

Janessabourne 14th April 2011 04:31 AM

Re: What the different between print and echo
 
As for echo statement.it doesn't return value of , the print which always return one and 0.


xrvel 14th April 2011 06:11 AM

Re: What the different between print and echo
 
For example, you can use this with print.
PHP Code:

mysql_query() or print(mysql_error()); 

You can't do it with echo
PHP Code:

mysql_query() or echo(mysql_error());// will fail 


ronspals 14th April 2011 07:54 AM

Re: What the different between print and echo
 
Echo can take multiple parameters to echo.This is not true with print. The "echo" and "print" tests can be tailored depending on what you are actually using it for. In general echo is faster, although there's cases where print can be faster.

oknoorap 18th April 2011 02:25 AM

Re: What the different between print and echo
 
echo vs. print

Benchmarks :

Code:

echo ''
Total time: 159 µs

Code:

print ''
Total time: 138 µs

Code:

echo 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa'
Total time: 194 µs

Code:

print 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa'
Total time: 178 µs

Code:

echo 'aaaaaaa'.'aaaaaaa'.'aaaaaaa'.'aaaaaaa'
Total time: 217 µs

Code:

echo 'aaaaaaa','aaaaaaa','aaaaaaa','aaaaaaa'
Total time: 521 µs

Code:

print 'aaaaaaa'.'aaaaaaa'.'aaaaaaa'.'aaaaaaa'
Total time: 245 µs

Code:

$ var = 'aaaaaaa';
echo 'aaaaaaa'.$ var.'aaaaaaa'.

Total time: 622 µs

Code:

$ var = 'aaaaaaa';
echo 'aaaaaaa',$ var,'aaaaaaa',

Total time: 794 µs

Code:

$ var = 'aaaaaaa';
print 'aaaaaaa'.$ var.'aaaaaaa'.

Total time: 890 µs

Code:

$ var = 'aaaaaaa';
echo $ var.$ var.$ var.$ var

Total time: 937 µs

Code:

$ var = 'aaaaaaa';
echo $ var,$ var,$ var,$ var

Total time: 894 µs

Code:

$ var = 'aaaaaaa';
print $ var,$ var,$ var,$ var

Total time: 1009 µs

remove space between dollar and var.

dealsbells 29th April 2011 11:27 AM

Re: What the different between print and echo
 
Echo is a statement print is a function.echo print the multiple function but print function print statement.The only difference between print & echo is that both of them displays leads to different format.

CodeMyConcept 29th April 2011 01:51 PM

Re: What the different between print and echo
 
Both do the same job, but there is a slight difference between print and echo so it usually comes down to a matter of personal preference.

UMS 1st May 2011 01:32 AM

Re: What the different between print and echo
 
Given the programming language wasn't specified, I'll assume bash as the language.

In which case,

echo is a builtin bash function, whereas print is an external command and therefore requires the overhead (albeit small) to fork a new process.


All times are GMT -6. The time now is 03:02 AM.