function - Return vs echo | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

function - Return vs echo

When we want to print something that is calculated on a function is better use echo inside the function or we just use return and use echo when we call that function?

5th Feb 2018, 5:53 PM
Rachid Antunes
Rachid Antunes - avatar
1 Answer
+ 3
Do you plan on doing anything further with the value? If not, echo it from the function and don't waste resources returning the value back to the code that called the function. If the code that called the function is going to use the value elsewhere, then you'll want to return the value. That'll return the value so you can utilize it outside of the function.
5th Feb 2018, 6:10 PM
Fata1 Err0r
Fata1 Err0r - avatar