PHP custom function variable function
In the previous variable section, we learned about variable variables. Variable function is just a variant and deformed expression of variable variable.
Variable function, we will also call it variable function. A brief review of the previous knowledge points:
<?php $hello = 'world'; $world = '你好'; //输出的结果为:你好 echo $$hello; ?>
Because $hello is first interpreted as world, and then the $ sign is added before world to output: Hello.
The usage of variable functions is like this:
<?php function demo(){ echo '天王盖地虎'; } function test(){ echo '小鸡炖蘑菇'; } $fu = 'demo'; //把$fu变为了demo,把demo后加上了一个括号,就执行函数了 $fu(); //把$fu的值改为test字符串再试试? ?>
It is recommended that when you are learning basic grammar, you should not think about the final processing scenario, because the final processing scenario has been told to you. If you don’t have a grammatical foundation, you won’t understand.
For example: variable function, also called variable function. It can be used in future MVC, object-oriented design patterns, etc. So, don’t delve into it now.