I see you are posting comments still which suggest you are confused because you don't understand the flow of the code. Perhaps this will help you (particularly with Mathias R. Jessen's answer).
So take these two functions again:
function sayHelloLater() {
return 'Hello';
}
function sayGoodbyeNow() {
echo 'Goodbye';
}
Now if you do this:
$hello = sayHelloLater();
$goodbye = sayGoodbyeNow();
echo $hello;
echo $goodbye;
You will be left with 'GoodbyeHello' on your screen.
Here's why. The code will run like this:
$hello = sayHelloLater(); ---->-------->-------->------->------>--
¦
¦ ^ ¦
¦ ¦ Call the function
v ¦ ¦
¦ ^ ¦
¦ ¦ v
¦
v "return" simply sends back function sayHelloLater() {
¦ 'Hello' to wherever the <----<---- return 'Hello';
¦ function was called. }
v Nothing was printed out
¦ (echoed) to the screen yet.
¦
v
$hello variable now has whatever value
the sayHelloLater() function returned,
so $hello = 'Hello', and is stored for
whenever you want to use it.
¦
¦
v
¦
¦
v
$goodbye = sayGoodbyeNow(); ---->-------->-------->------->------
¦
¦ ^ ¦
¦ ¦ Call the function
v ¦ ¦
¦ ^ ¦
¦ ¦ v
¦ ¦
v ¦ function sayGoodbyeNow() {
¦ echo 'Goodbye';
¦ The function didn't return }
¦ anything, but it already
v printed out 'Goodbye' ¦
¦ v
¦ ^
¦ ¦ "echo" actually prints out
v <-----------<-----------<--------- the word 'Goodbye' to
¦ the page immediately at
¦ this point.
¦
v
Because the function sayGoodbyeNow() didn't
return anything, the $goodbye variable has
a value of nothing (null) as well.
¦
¦
¦
v
¦
¦
¦
v
echo $hello; -------->-------> Prints 'Hello' to the screen at
this point. So now your screen says
¦ 'GoodbyeHello' because 'Goodbye' was
¦ already echoed earlier when you called
¦ the sayGoodbyeNow() function.
v
echo $goodbye; ------>-------> This variable is null, remember? So it
echoes nothing.
¦
¦
¦
v
And now your code is finished and you're left with
'GoodbyeHello' on your screen, even though you echoed
$hello first, then $goodbye.