开发者

PHP - cooler function parameter

I have this:

function boo($show_one = false){
  if(!show_one) return 1; else return 2;
}

how can I call boo 开发者_开发知识库like this:

boo(SHOW_ALL);

instead of boo(false). I see some native php function have parameters like that which make the code more easy to read


define("SHOW_ALL", false);
define("SHOW_ONE", true);

would correspond to your code there. But I'd reccomend using numbers instead of booleans. What if next weeks you decide to have a SHOW_PAGINATED option?


define('SHOW_ALL', true);

function boo($show_one = false){
  if(!$show_one) return 1; else return 2;
}

boo(SHOW_ALL);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜