Darkmatter5 Posted July 11, 2008 Share Posted July 11, 2008 Say I had a page of functions that I call within various pages to generate various aspects of the pages. Now say I have a function within that functions page that needs to call another function. How do I go about calling a function from within another function? Example: function hi() { echo "Hi!" } function hello() { echo "Hello!" (and also the output of hi()); } How do I get hello() to have the following output? "Hello! Hi!" Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/114320-running-a-function-from-with-another-function/ Share on other sites More sharing options...
wildteen88 Posted July 11, 2008 Share Posted July 11, 2008 use return not echo in the hi function. Quote Link to comment https://forums.phpfreaks.com/topic/114320-running-a-function-from-with-another-function/#findComment-587859 Share on other sites More sharing options...
craygo Posted July 11, 2008 Share Posted July 11, 2008 just call the other function in it <?php function hi() { $ret = "Hi!"; return $ret; } function hello() { $ret = "Hello! "; $ret .= hi(); return $ret; } echo hello(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/114320-running-a-function-from-with-another-function/#findComment-587861 Share on other sites More sharing options...
discomatt Posted July 11, 2008 Share Posted July 11, 2008 Or to remove a bit of redundancy <?php function hi() { return "Hi!"; } function hello() { return "Hello! " . hi(); } echo hello(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/114320-running-a-function-from-with-another-function/#findComment-587907 Share on other sites More sharing options...
Guest Xanza Posted July 11, 2008 Share Posted July 11, 2008 These are called multidimensional functions correct? Quote Link to comment https://forums.phpfreaks.com/topic/114320-running-a-function-from-with-another-function/#findComment-587932 Share on other sites More sharing options...
.josh Posted July 11, 2008 Share Posted July 11, 2008 AFAIK there's no special term for calling a function from inside another function. AFAIK the only "multidimensional" anything out there is multidimensional arrays. Quote Link to comment https://forums.phpfreaks.com/topic/114320-running-a-function-from-with-another-function/#findComment-587937 Share on other sites More sharing options...
discomatt Posted July 11, 2008 Share Posted July 11, 2008 No, it's simply calling a function in a function. You do it all the time, just with our examples, both functions are user defined. You're thinking arrays, where an array within an array creates a multidimensional array Quote Link to comment https://forums.phpfreaks.com/topic/114320-running-a-function-from-with-another-function/#findComment-587938 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.