What is the difference between PHP echo and PHP return in plain English?

I’m going to give a completely non-technical answer on this one.

Let’s say that there is a girl named Sally Function. You want to know if she likes you or not. So since you’re in grade school you decide to pass Sally a note (call the function with parameters) asking her if she likes you or not. Now what you plan on doing is asking her this and then telling everyone what she tells you. Instead, you ask her and then she tells everyone. This is equivalent to returning (you getting the information and doing something with it) vs her echoing (telling everyone without you having any control).

In your case what is happening is that when Sally echos she is taking the control from you and saying “I’m going to tell people this right now” instead of you being able to take her response and do what you wanted to do with it. The end result is, however, that you were telling people at the same time since you were echoing what she had already echoed but didn’t return (she cut you off in the middle of you telling your class if she liked you or not)

Leave a Comment