Xname Posted May 17, 2012 Share Posted May 17, 2012 HI...I hope u r all fine. I am using nested function ih php. this is not working.Here is the code. <?php $array = array('a','b','c'); big_func($array); function big_func($arr) { function func1($arr) { foreach($arr as $list1){ echo $list1.'<br />'; } function func2($arr) { foreach($arr as $list2){ echo '<b>'.$list2.'</b><br />'; } } function func3(){ $arra = array('d','e','f'); func1($arra); } } } ?> This is not working.What is the problem with this code? please help me .....thanks........ Quote Link to comment https://forums.phpfreaks.com/topic/262662-nested-function-does-not-work/ Share on other sites More sharing options...
kicken Posted May 17, 2012 Share Posted May 17, 2012 The reason your script does not doing anything is because you never call one of those inner functions, all you ever do is define them. That said, PHP doesn't really support nested functions. The script will parse successfully, but if you ever call the outer function (big_func in your case) more than once you'll get a Fatal error about re-defining the functions. There really isn't any pratical use for trying to do a nested function setup, just declare all the functions at the top global level and then use them as needed elsewhere. Quote Link to comment https://forums.phpfreaks.com/topic/262662-nested-function-does-not-work/#findComment-1346265 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.