开发者

What is this "iif" in php means?

开发者 https://www.devze.com 2022-12-17 00:35 出处:网络
Has anyone see this \"iif\" in php before? What is that actually? I try to search the document开发者_开发百科ation for it in php.net but I cant found any. Anyone can give a simple example of how to us

Has anyone see this "iif" in php before? What is that actually? I try to search the document开发者_开发百科ation for it in php.net but I cant found any. Anyone can give a simple example of how to use this "iif"?


The function iif does not exist in the standard PHP libraries. But in most cases it is a 'short if expression' such as: (condition ? true : false).


This is part of PHPKit. It stands for 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."


copied from 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');

0

精彩评论

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