Internal function of php custom function

Internal function means that a function is declared inside the function.

Notes:

1. The internal function name cannot be an existing function name

2. Assume that an internal function is defined in function a, You cannot use function a twice.

Let’s look at the code below, you will learn it quickly:

<?php
function foo()
{
   echo '我是函数foo哟,调一下我才会执行定义函数bar的过程<br />';
 function bar()
 {
      echo '在foo函数内部有个函数叫bar函数<br />';
 }


}

//现在还不能调用bar()函数,因为它还不存在
bar();

foo();

//现在可以调用bar()函数了,因为foo()函数的执行使得bar()函数变为已定义的函数

bar();

//再调一次foo()看看是不是会报错?
foo();

?>

You will find that a bar function is defined inside the foo() function above, which is the inner function number .

After careful observation and experimentation, you will draw the following conclusions:

1. Calling foo() twice will report an error

2. If you do not adjust the foo() function The bar function cannot be executed because bar is inside foo

Continuing Learning
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
function foo()
{
echo 'foobar<br />';
function bar()
{
echo 'foobar<br />';
}
}
//bar()
bar();
foo();
//bar()foo()使bar()
bar();
//foo()
foo();
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
submitReset Code
图片放大关闭