+ 1
Whats the difference between echo and return?
2 Answers
+ 5
echo: is an output to screen (something like "print on screen); return: returns a value to who called the function
0
//example 1 - Just return value and need "echo" to print
function myReturn($para){
$num=$para+2;
return $num; //This will give back 2 added $para(as $ reNum) to who called
}
$reNum=myReturn(5);
//function will give back 7 to $reNumand it won't be printed..
//If you want to print
echo $reNum; // This will print 7
//example 2 - direct print value when function was called
function myEcho($para){
$num=$para+2;
echo $num;
}
myEcho(5); //function will print 7 to screen
$reNum=myEcho(5);
//funtion won't give back anything to $reNum and $reNum has no value
echo $reNum(5); //This won't print nothing cuz $reNum has no value...