1

Possible Duplicate:
What is the PHP ? : operator called and what does it do?

Can someone please tell me what this 'return' php code means / does:

return ($status=='SUCCESS' && $blocked=='YES') ? $reason : false;

I'm familiar with the regular return $variable type of statements in php, but I don't get what the specific brackets ( ) and ? question marks and the ": false" does.

(this is the return statement at the end of a php function)

Community
  • 1
  • 1
Marc Dubois
  • 19
  • 1
  • 4
  • Almost (its very similar but the link's question lacks the &&). I didn't find it when i was searching. – Marc Dubois Aug 08 '12 at 00:46
  • Yes, sorry, I was interrupted. This is missing this very important question here as reference: [Reference - What does this symbol mean in PHP?](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) - Whenever you run about some symbol you do not understand, that is a really good reference (next to the manual, it's sometimes hard to even search for these that's why that reference is worth to bookmark). – hakre Aug 08 '12 at 01:03

3 Answers3

2

It's a ternary statement. It's basically a shorthand notation for if/else.

In your example it would read like: If $status is equal to "success" and $blocked is equal to "Yes" return $reason, else, return false;

John Conde
  • 217,595
  • 99
  • 455
  • 496
1

That's a ternary, or conditional operator, it's the same as if you had:

if($status=='SUCCESS' && $blocked=='YES'){
return $reason;}
else{
return false;
}
Robot Woods
  • 5,677
  • 2
  • 21
  • 30
0

It means the same as this:

if($status == 'SUCCESS' && $blocked == 'YES')
{
    return $reason;
}
else
{
    return false;
}
PriestVallon
  • 1,519
  • 1
  • 22
  • 44