php default arguments

前端 未结 4 640
北海茫月
北海茫月 2020-12-03 13:58

In PHP, if I have a function written like this

function example($argument1, $argument2=\"\", $argument3=\"\")

And I can call this function

4条回答
  •  执念已碎
    2020-12-03 14:39

    It depends on spesification of function.

    function a($b=true,$c=false){
     echo $b?'true':'false';
     }
    

    executing

     a(NULL, 1);
    

    results : false. but simply a() results : true

    That means you want default argument, then you should use as default:

     a(true, 1);
    

提交回复
热议问题