0

i'm noob with php and i was wondering what that expression mean:

$extra_adults = ($num_adults > $people) ? $num_adults-$people : 0; 

can someone explain me please?

Thank you very much for your time.

Max
  • 39
  • 7

2 Answers2

1

This is called ternary operator. A short form of if else statment in php.

Readmore at this link http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary

1

Its a Ternary operator statement. E.g.

$x = $valid ? 'yes' : 'no';

It will assign yes to $x if $valid is true and no if $valid is false.

So, as per your statement which is:

$extra_adults = ($num_adults > $people) ? $num_adults-$people : 0; 

If $num_adults is greater than $people then it will do $num_adults -$people and assing the result to $extra_adults, else it will assign 0 to $extra_adults.

Tom
  • 3,031
  • 1
  • 25
  • 33