dss087358 2018-12-18 20:04
浏览 160

从函数PHP调用函数

Can anyone explain to me what is actually going on in the function?

function f($b=0)
{
    echo $b.',';
    /*otuput is 0,1,2,3,4,5,3,4,2,3,4,5,3,*/

    if ($b<3)
    {
        /*echo $b.',';
        when echo is here, otuput is 0,1,2,2,*/

        for ($a=0;$a<3;$a++)
        {
            /*echo $b.',';
            when echo is here, otuput is 0,1,2,3,4,2,3,1,2,3,4,2,*/

            f(++$b);
        }
    }
}

f();

Why is output not 0,1,2,0,1,2,0,1,2,? And how to do with the calling same function from function?

  • 写回答

2条回答 默认 最新

  • drgaeqdqiiyg14608 2018-12-18 20:51
    关注

    First of all it calls f(0) so it displays 0.

    Then it calls f(1), f(2) & f(3) respectively.

    f(1): It displays 1 and runs f(2), f(3) & f(4).

    f(2): It displays 2 and runs f(3), f(4) & f(5).

    f(3): It displays 3 only

    f(4): It displays 4 only

    f(5): It displays 5 only

    ...

    So:

    f(0):
        {
        0,
        f(1): 
            {
            1, 
            f(2): 
                {
                2, 
                f(3): 
                    {
                    3
                    }, 
                f(4): 
                    {
                    4
                    }, 
                f(5): 
                    {
                    5
                    } 
                },
            f(3):
                {
                3
                },
            f(4):
                {
                4
                }
            },
        f(2):
            {
            2, 
            f(3): 
                {
                3
                }, 
            f(4): 
                {
                4
                }, 
            f(5): 
                {
                5
                } 
            },
        f(3):
            {
            3
            }
        }
    

    So the output is: 0,1,2,3,4,5,3,4,2,3,4,5,3,

    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路