Reputation: 11
In the following code, why does the phrase "example" only output once if both foo() and bar() are called>
<?php
function foo()
{
function bar()
{
echo "example\n";
}
}
foo();
bar();
?>
Upvotes: 0
Views: 22
Reputation: 4012
You want to be declaring your functions separately like so:
<?php
function foo()
{
bar();
}
function bar()
{
echo "example\n";
}
foo();
bar();
?>
Nesting your functions inside each other doesn't really serve any purpose that i can think of.
Upvotes: 1