+ 2
echo VS return
Could you help me to understand what is the difference between echo and return please?
1 Odpowiedź
+ 2
I assume you mean on PHP? Well "return" does the same thing in most languages anyway.
"echo" prints something to the screen or console. For example, this will write "Hello World".
echo "Hello World";
"return" is used within functions, loops or other methods to output a value which you can assign to a variable or input into another function etc.. Here's an example.
function double($x){
return $x * 2;
}
$four = double(2);
$eight = double(double(2));
//4 is now stored in $four
//8 is stored in $eight