| Welcome to zetaNetwork. We hope you enjoy your visit. You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as viewing zetaNetwork exclusive tutorials and articles, and access to our code snippets section. Registration is simple, fast, and completely free. Click Here To Register If you're already a member please log in to your account to access all of our features: |
| Echo vs Print | |
|---|---|
| Tweet Topic Started: May 26 2011, 03:39 PM (14,367 Views) | |
| Pro | May 26 2011, 03:39 PM Post #1 |
|
Underground Coding
![]()
|
Echo vs Print Time: 5 Minutes Difficulty: Easy Since Oracle asked for it, here it is. What's the difference between PHP's echo and print? They both look similar in both syntax and function. Let's look at an example: Both of these statements will output "Foo's" resulting in "Foo'sFoo's". Both also support escape sequences. Now the big difference that you can't really notice is that print will always return 1. In this example since print always returns 1 the if statement will always be true so it will print print 'foos' which will print foos1. Echo doesn't return anything when content is printed. The benefit of using echo though, is that you can pass multiple strings to be echoed through parameters. It is actually faster, in fact, to echo multiple strings through parameters instead of concatenation. Would actually be faster than
Echoing content instead of printing it is actually faster as a whole: http://www.phpbench.com/ Also some people think that echo and print are functions and as such must be called like so: echo() and print(). This is false, echo and print are not functions but language constructs and therefore do not need parenthesis. Well I hope you got some useful information from this. If you have any questions or comments post them here
|
|
Pro | zetaNetwork Instructor & Admin I Coded Most Of The Smexy Stuff You See ![]() PM Me Any Questions Need live support? Click here. | |
| Offline Profile | Quote ^ |
| VoidPC | May 26 2011, 11:46 PM Post #2 |
Getting Into The Groove
|
I understand it now. Thanks for the tut, Pro.
|
| Offline Profile | Quote ^ |
| Pro | May 27 2011, 01:21 AM Post #3 |
|
Underground Coding
![]()
|
No problem. If you ever need any help let me know. |
|
Pro | zetaNetwork Instructor & Admin I Coded Most Of The Smexy Stuff You See ![]() PM Me Any Questions Need live support? Click here. | |
| Offline Profile | Quote ^ |
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| « Previous Topic · Tutorials · Next Topic » |











2:34 PM Jul 11