0

Where can I find documentation for the following code?

$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

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
qaisjp
  • 722
  • 8
  • 31

1 Answers1

4

It's the ternary operator, and it's a way to consolidate a simple if/else expression.

From the docs:

// 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'];
}
nickb
  • 59,313
  • 13
  • 108
  • 143