UrbanDweller Posted November 5, 2011 Share Posted November 5, 2011 Hey ive been wanting to know how to make a function call another function which will then create a variable which i can send back to first function where i can use it. I tried somthing like this <?php a(); function a($wall) { b(); echo $wall; } function b() { $wall = "test"; #a($wall); } ?> Thats what i tried but ofcourse didnt work, how would i go about doing this? Thanks. Link to comment https://forums.phpfreaks.com/topic/250501-sending-variables-back-to-parent-function/ Share on other sites More sharing options...
freelance84 Posted November 5, 2011 Share Posted November 5, 2011 Do you mean like this? <?php function one($varA){ $varB = $varA.'B'; two($varB); } function two($varB){ echo $varB; } echo one('A'); ?> Link to comment https://forums.phpfreaks.com/topic/250501-sending-variables-back-to-parent-function/#findComment-1285234 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2011 Share Posted November 5, 2011 Functions RETURN the results that they produce. The point of functions are they (optionally) accept call time parameters, produce some useful result, and then return that result at the point that they were called. You can either assign the returned result to a variable or use it as a parameter in another function call or use it as a value in a language construct. <?php a(); function a() { // use the returned value as a parameter/value in another function/language construct echo b(); // or assign the returned value to a variable $c = b(); echo $c; } function b() { return "test"; // ... code that produces some useful result and returns it to the calling code } ?> Link to comment https://forums.phpfreaks.com/topic/250501-sending-variables-back-to-parent-function/#findComment-1285263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.