开发者

Syntax to check isset using comparison operators

Just like how we do in other languages to check for a condition in one line. Is it possible to do it in PHP?开发者_开发问答

in java

boolean val = (a == b) ? true : false;

similarly is it possible in PHP.

If yes, the can this be done for the isset keyword?


Yes, absolutely. PHP supports the ?: ternary operator as well. For example:

$foo = isset($_POST['foo']) ? $_POST['foo'] : '';


Yes, it's possible to use the ternary operator in PHP. Replacing (a == b) with isset(expression) (returns boolean value) should do the trick. Just make sure that the = operator doesn't take precedence. It may not be necessary but I'd wrap the ternary statement in between curved brackets.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜