PHP中的这种语法(page = $ page?$ page:'default')是什么意思? [英] What does this syntax ( page = $page ? $page : 'default' ) in PHP mean?
本文介绍了PHP中的这种语法(page = $ page?$ page:'default')是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是PHP新手。我在 WordPress 中遇到了这种语法。该代码的最后一行是做什么的?
I'm new to PHP. I came across this syntax in WordPress. What does the last line of that code do?
$page = $_SERVER['REQUEST_URI'];
$page = str_replace("/","",$page);
$page = str_replace(".php","",$page);
$page = $page ? $page : 'default'
推荐答案
PHP中的条件运算符。
It's an example of the conditional operator in PHP.
这是以下形式的缩写:
if (something is true ) {
Do this
}
else {
Do that
}
请参见 使用If / Else三元运算符
http:// php。 net / manual / en / language.operators.comparison.php 。
See Using If/Else Ternary Operators http://php.net/manual/en/language.operators.comparison.php.
这篇关于PHP中的这种语法(page = $ page?$ page:'default')是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文