You can even nest functions in PHP. However, much as with conditional functions, the internal function isn't seen by PHP until the enclosing function is called. You can see an example in phpnestedfunction.php, Example 4-14, where we call a function within a function, but only after the enclosing function is called. Example 4-14. Using variable functions, phpnestedfunction.php<HTML> <HEAD> <TITLE>Nesting Functions</TITLE> </HEAD> <BODY> <H1>Nesting Functions</H1> <?php function enclosing_function() { echo "Hello from the enclosing function!<BR>"; function created_function() { echo "Hello from the nested function!<BR>"; } } enclosing_function(); created_function(); ?> </BODY> </HTML> The results appear in Figure 4-14, where you can see that both functions have run. Figure 4-14. Nesting functions. |