eldan88 Posted April 22, 2012 Share Posted April 22, 2012 Hey, I wanted to know if there is any difference between catching a return value and assigning into a variable, and just catching the value when when you just simply call the function on its own. Here is what I mean below In the first example I called the return by simple calling the function. In the second example I catched the return value through a variable, and then echoed it out. <?php // Example 1 function text (){ $string = "this is a string </br>"; return $string;} echo text(); // Example 2 function text (){ $string = "this is a string </br>"; return $string; } $new_value = text(); echo $new_value; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/261427-do-return-values-always-need-to-be-catched-into-a-variable/ Share on other sites More sharing options...
MarPlo Posted April 22, 2012 Share Posted April 22, 2012 Hi, Storing the return data into a variable is useful when you want to use again, or manipulate that data in your code. For example, calling a function three times requires more memory than storing the value in a variable and using the variable. Quote Link to comment https://forums.phpfreaks.com/topic/261427-do-return-values-always-need-to-be-catched-into-a-variable/#findComment-1339630 Share on other sites More sharing options...
eldan88 Posted April 22, 2012 Author Share Posted April 22, 2012 thanks dude! Quote Link to comment https://forums.phpfreaks.com/topic/261427-do-return-values-always-need-to-be-catched-into-a-variable/#findComment-1339639 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.