Can I include a function inside of another function?

后端 未结 6 1170
遥遥无期
遥遥无期 2021-01-02 06:28

Is it possible to include one function inside another? To learn functions, I\'m trying to create a combat sequence using PHP. The sequence would look like this:

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 06:43

    If you want to define functions within function in PHP you can do it like this:

    function a()
    {
        function b()
        {
            echo 'I am b';
        }
        function c()
        {
            echo 'I am c';
        }
    }
    a();
    b();
    c();
    

    You must call the parent function first, then the functions inside.

提交回复
热议问题