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
  • 42,835
  • 20
  • 145
  • 262
qaisjp
  • 712
  • 8
  • 30

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
  • 58,150
  • 12
  • 100
  • 138