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);
精彩评论