Question:
What is a ternary operator?
$variable = condition ? if true : if false
An example is shown below:
$style = isset($_GET['style']) ? $_GET['style'] : 'default';
This checks whether variable $_GET['style'] is set. If it is variable $style is given this value. Alternatively, variable $style is given the value 'default'.
Part 1 | Part 2 | Part 3 |
$variable = condition | if true | if false |
condition we're testing ? | what happens if condition is true | what happens if condition is false |
Taxonomy: