A function inside an if structure

前端 未结 5 603
执笔经年
执笔经年 2020-12-31 02:42

can I put a function in PHP inside a if structure? like this:



        
5条回答
  •  -上瘾入骨i
    2020-12-31 03:35

    As middaparka says, this is perfectly legal, but in terms of using it, you might want to check if a function exists before declaring it:

    if (!function_exists("foo"))
    {
        function foo()
        {
            return "bar";
        }
    }
    
    • function_exists documentation

提交回复
热议问题