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. Quote Link to comment 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'); ?> Quote Link to comment 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 } ?> Quote Link to comment 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.