我在哪里可以找到这方面的文件?

时间:2012-07-19 16:30:57

标签: php

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

$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

1 个答案:

答案 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'];
}