php php中的这个“iif”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2092642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is this "iif" in php means?
提问by mysqllearner
Has anyone see this "iif" in php before? What is that actually? I try to search the documentation for it in php.net but I cant found any. Anyone can give a simple example of how to use this "iif"?
有没有人以前在 php 中看到过这个“iif”?那究竟是什么?我尝试在 php.net 中搜索它的文档,但找不到任何文档。任何人都可以举一个简单的例子来说明如何使用这个“iif”?
采纳答案by Skilldrick
This is part of PHPKit. It stands for Immediate If.
这是 PHPKit 的一部分。它代表Immediate If。
The syntax is:
语法是:
iif(condition, true statement, false statement);
@VolkerK's comment should be noted: "And keep in mind that iff(x,y,z) evaluates both y and z (no lazy function parameter evaluation in php) while x?y:z evaluates only y or z."
应该注意@VolkerK 的评论:“请记住,iff(x,y,z) 对 y 和 z 进行评估(php 中没有惰性函数参数评估),而 x?y:z 仅对 y 或 z 进行评估。”
回答by Kolky
The function iifdoes not exist in the standard PHP libraries. But in most cases it is a 'short if expression' such as: (condition ? true : false).
该函数iif在标准 PHP 库中不存在。但在大多数情况下,它是一个“短,如果表达”,如:(condition ? true : false)。
回答by Dyno Fu
copied from http://www.phpfreaks.com/forums/index.php?topic=124215.0
复制自http://www.phpfreaks.com/forums/index.php?topic=124215.0
function iff($tst,$cmp,$bad) {
return(($tst == $cmp)?$cmp:$bad);
}
echo iff('one','two','three');
echo iff('four','four','ok');

