Operator "?" in PHP, what is it for?

Asked

Viewed 406 times

0

I’m studying php, I took a code to move and I’m not finding reference to the question mark in php, which serves in the example below, for what it serves.

$dinheiro = $debito <= 1 ? FALSE : TRUE;
  • It’s the ternary operator, take a look at the link that rray posted that has great answers.

1 answer

4

It’s called the ternary operator.

This means: if the value of $debit is less than or equal to one, the variable $money gets the value of FALSE, otherwise it gets the value of True.

This can be compared to:

if($debito<=1)
{
   $dinheiro = false;
}
else
{
   $dinheiro = true;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.