Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMiguel Nunez
3,266 PointsWhat's the difference between an echo and a return.?
I notice some examples like for example math situations will tend to give me a situation that equals the answer so for example 1+1= 2 I notice echo and a return gives the same answer and response when I see an execution of it if they as so different what are they doing given the same results and same effects why would I bother with a return if I can just do the same thing with just use an echo all the time.
Aayatullah Miyan
4,687 PointsAt first part the value is passed from addup(10,15) to the addup($a,$b). Then the sum is done in $c and it is echoed. In secord part, the value is passed from multi(10,15) to the multi($num1,$num2) then the product is returned using return to multi() in the line containing echo "<br> The value of the product is". multi(10,15) making it echo the product.
<?php
function addup($a,$b){
$c=$a+$b;
echo $c." This is the sum";
}
addup(10,15);
?>
//
<?php
function multi($num1,$num2){
return $num1*$num2;
}
echo "<br>The value of the product is " .multi(10,15);
?>```
Jesus Mendoza
23,289 PointsJesus Mendoza
23,289 Points