0

在哪里可以找到以下代码的文档?

$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!

http://viper-7.com/H8upUh

4

1 回答 1

4

它是三元运算符,它是一种合并简单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'];
}
于 2012-07-19T16:32:42.193 回答