PHP中的语法是什么? [英] What is this syntax in PHP?
本文介绍了PHP中的语法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在修改脚本以更好地适应我的需要,我在代码中遇到了这一行:
I'm working on modifying a script to better suit my needs, and I came across this line in the code:
return isset($_COOKIE[$parameter_name]) ? $_COOKIE[$parameter_name] : "";
我知道函数本身本质上是一个cookie getter方法,但我不知道什么该语法(即?和:)意味着。
I know that the function itself is essentially a cookie getter method, but I'm not quite sure what that syntax (i.e. the "?" and ":") means. I apologize if this is a really dumb question, but could someone explain it to me?
推荐答案
这是一个三元操作,基本上是一个更紧凑的写if / then / else的方法。
It's a ternary operation and is basically a more compact way of writing an if/then/else.
所以在你的代码示例中,它被使用,而不必写:
So in your code sample it's being used instead of having to write:
if (isset($_COOKIE[$parameter_name])) {
return $_COOKIE[$parameter_name];
} else {
return "";
}
这篇关于PHP中的语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文