dvayne Posted January 15, 2008 Share Posted January 15, 2008 whats the difference between this <?php function addition ($a, $b) { $sum=$a+$b; echo "the sum is" .$sum; } ?> <html> <head> <title>Untitled Document</title> </head> <body> <?php addition (8,2); ?> </body> </html> and this <?php function addition ($a, $b) { $sum=$a+$b; echo "the sum is" .$sum; return; } ?> <html> <head> <title>Untitled Document</title> </head> <body> <?php addition (8,2); ?> </body> </html> and this <?php function addition ($a, $b) { $sum=$a+$b; echo "the sum is" .$sum; return $sum; } ?> <html> <head> <title>Untitled Document</title> </head> <body> <?php addition (8,2); ?> </body> </html> please help me.. Quote Link to comment https://forums.phpfreaks.com/topic/86129-use-of-return-statement/ Share on other sites More sharing options...
nikefido Posted January 15, 2008 Share Posted January 15, 2008 you can use functions to return data. If your function returns the result of a math problem (like your last example), you can assign that returned value to a variable: <?php function addition ($a, $b) { $sum=$a+$b; echo "the sum is" .$sum; return $sum; } $myReturnedVariable = addition(5,6); //$myReturnedVariable will = 11 ?> The first example echo's "the sum is whatever" and does not return anything. I THINK the 2nd one is just wrong. (can anyone confirm that?) The third example does what I showed you above. Hope this helps! Quote Link to comment https://forums.phpfreaks.com/topic/86129-use-of-return-statement/#findComment-439857 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 yeah i also think the second one is wrong because you aren't saying what to return. Php can't mind read. If it could life would be easy. Quote Link to comment https://forums.phpfreaks.com/topic/86129-use-of-return-statement/#findComment-439859 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.