我在哪里可以找到以下代码的文档?
$a = .01 * rand(0, 100) >= .5; //I don't need doc for this line, its for generating a random boolean!
$b = "it was true!";
$c = "it was false!";
echo "Guess what, " . ( $a ? $b : $c ); // I need documentation for how this works!
答案 0 :(得分:4)
这是ternary operator,它是一种合并简单if/else
表达式的方法。
来自文档:
// Example usage for: Ternary Operator
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];
// The above is identical to this if/else statement
if (empty($_POST['action'])) {
$action = 'default';
} else {
$action = $_POST['action'];
}