Possible Duplicate:
What is the PHP ? : operator called and what does it do?
What does this mean in longform? I haven't seen a line like this.
$max_o = $max_o > $o ? $max_o : $o;
Possible Duplicate:
What is the PHP ? : operator called and what does it do?
What does this mean in longform? I haven't seen a line like this.
$max_o = $max_o > $o ? $max_o : $o;
This is the same as saying:
if($max_o <= $o) {
$max_o = $o;
}
But in longhand it says
if($max_o > $o) {
$max_o = $max_o;
}
else {
$max_o = $o;
}
Which is rather pointless. This is a poor usage of the ternary operator since my first simple example would do just as well.
This is the php ternary operator. It is like the following code:
if ($max_o > o)
$max_o = $max_o;
else
$max_o = $o;
The question mark is a ternary operator
it is the same as typing
if ($max_o > $o) {
$max_o = $max_o;
} else {
$max_o = $o;
}
What you actually want to write is:
$max_o = max($max_o, $o);
Apart from that, the thing's called ternary operator and is a shortcut syntax for an if
-statement.