Page 1 of 1

Diffrence Between Echo and Print??

Posted: Sun Dec 10, 2006 8:21 pm
by ThichHeaded
I don't know how stupid questions can get on here but I have a feeling that I might win some type of award for it.

Anyway.

The question is this. What is the difference between echo and print?

I made a simple code to show my point.

(sorry for code below I am trying to help someone else with php altho I am limited in my knowledge.)

Code: Select all

<?php
# This is a Var test code, just showing someone how vars can be the same and diffrent..####


$Kevin = 'Kevin';
$Nkevin = 'Ed';
$nkevin = 'Maybe Kevin';

#####    Rest below is the code that is with the Variables vars here.  
#####    It isn't hard just remove the HTML coding there to see the php code itself.  


?>

<!-- Code is above here.. You Cant see it tho.. -->
<!-- PHP can not be seen in HTML format, only the Code it produces. -->

<FONT SIZE="3"><FONT color="Red"><B>Red</B></FONT> is $Kevin<BR>
<FONT color="Blue"><B>Blue</B></FONT> is $Nkevin<BR>
<FONT color="Green"><B>Green</B></FONT> is $nkevin<BR><BR></FONT>

<FONT SIZE="3">We went to meet <font color="red"><B><?php echo $Kevin;?></B></font>, but we found <font color="blue"><B><?php echo $Nkevin;?></B></font>. <font color="green"><B><?php print $nkevin;?></B></font> will be down the street.</FONT>
Now someone told me that I should never use print for some reason or another.. altho I cant remember. I always knew echo would print out whatever you had after echo whether it would be something like these below.

Code: Select all

echo $var;
or

Code: Select all

echo 'stuff here' or "stuff here";
So what is Print, In the last 3 yrs I have only come across it in one of those Dummy books. So this is farely new to me cause in most code I look at is always echo whatever.

Posted: Sun Dec 10, 2006 8:36 pm
by brendandonhue
print() is a function that returns a value. echo is a language construct.
http://www.faqts.com/knowledge_base/vie ... d/1/fid/40

Posted: Sun Dec 10, 2006 8:44 pm
by Oly
they do the same thing pretty much...

BUT!

With echo you can echo multiple things within echo, IE:

Code: Select all

<?php echo $var1,$var2; ?>
and with print you could only do:

Code: Select all

<?php print $var1; print $var2; ?>
with echo also you can't do:

Code: Select all

<?php $tenary = ($var1 == $var2) ? echo 'CHEESE!' : echo 'PICKLES!'; ?>
but you can do

Code: Select all

<?php $tenary = ($var1 == $var2) ? print 'CHEESE!' : print 'PICKLES!'; ?>
or

Code: Select all

<?php $tenary = ($var1 == $var2) ? 'CHEESE!' : 'PICKLES!'; ?>
and if you ever use

Code: Select all

<?=$var1?>
it is echo'ing it with a shorter syntax.

Posted: Mon Dec 11, 2006 5:55 am
by aaronhall
brendandonhue wrote:print() is a function that returns a value. echo is a language construct.
http://www.faqts.com/knowledge_base/vie ... d/1/fid/40
Both print and echo are language constructs. Echo does not return a value, and print always returns an integer '1'.

Re: Diffrence Between Echo and Print??

Posted: Mon Dec 11, 2006 6:16 am
by timvw
ThichHeaded wrote: The question is this. What is the difference between echo and print?
The answer can be found in the manual (so please stop wasting our time and do some research yourself).

Posted: Mon Dec 11, 2006 6:39 am
by ThichHeaded
From reading the manual I got that they are basically the same thing. Therefor someone told me it wasn't and I read that it was. I wanted to make sure.

I wasn't asking to take up your time, I was asking because I didn't understand. Next time I will not ask simple a simple questions.

Anyway thank you for your time.

Posted: Mon Dec 11, 2006 8:19 am
by aaronhall
Simple questions aren't a problem. It's usually a good idea, though, to briefly describe what you had already found, and why it wasn't sufficient in answering your question.