What is the difference between echo and print?
Regards,
Ezeekart Team,
Buy Mobile phone online
http://www.ezeekart.com
diff echo& print
Moderator: General Moderators
Re: diff echo& print
echo doesn't have a return value. print returns 1, always.
Re: diff echo& print
Echo can accept multiple values, where print only takes one argument.
Notice the last line actually uses comma, not periods, so it passed 4 items to echo:
This line doesn't have the overhead that the first line does of first concatenating all four items then passing that value to print.
Also this line doesn't have the overhead of parsing a double quoted string to and then passing the final value to print.
For small work, not such a big thing, but just an example of another difference. I myself have come to using the last sample.
-Greg
Code: Select all
$myname = 'Greg';
$mypassion = 'programming';
print 'Hello, my name is '.$myname.' and I love '.$mypassion;
print "Hello, my name is $myname and I love $mypassion";
echo 'Hello, my name is ',$myname,' and I love ',$mypassion;
Code: Select all
'Hello, my name is '
$myname
' and I love '
$mypassionAlso this line doesn't have the overhead of parsing a double quoted string to and then passing the final value to print.
For small work, not such a big thing, but just an example of another difference. I myself have come to using the last sample.
-Greg
- Tiancris
- Forum Commoner
- Posts: 39
- Joined: Sun Jan 08, 2012 9:54 pm
- Location: Mar del Plata, Argentina
Re: diff echo& print
Ah, the eternal question: echo or print?
I prefer to use print because I see it more "standard" or "nice" when using print_r, printf, sprintf, etc.
Just a matter of taste
I prefer to use print because I see it more "standard" or "nice" when using print_r, printf, sprintf, etc.
Just a matter of taste