2012-07-19 71 views
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

+0

如何三元作品? – Gntem 2012-07-19 16:31:52

+0

不太理解你的問題。我的意思是: var? var:var – qaisjp 2012-07-19 16:33:07

+0

我知道這個例子效率不高,但它只是一個例子。 – qaisjp 2012-07-19 16:33:44

回答

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']; 
} 
+0

感謝您的鏈接,將在9分鐘內打勾。 – qaisjp 2012-07-19 16:36:05

相關問題