0

Possible Duplicate:
Reference - What does this symbol mean in PHP?
What is the ?: Operator and what does it do?
The three different equals (=, ==, ===)

Can some explain how this works?

$xblgold = $xblgold == 1 ? "Yes" : "No";
echo $xblgold;
Community
  • 1
  • 1
AndrewFerrara
  • 2,383
  • 8
  • 30
  • 45
  • -1 for not using the search function before posting a question and for not bothering to choose a meaningful question title. – markus Mar 18 '11 at 08:54
  • @markus in all fairness, searching for operators is difficult on SO. – Gordon Mar 18 '11 at 08:55
  • @Gordon: Google search for 'php question mark' explains this too. – markus Mar 18 '11 at 08:58
  • @markus well, the PHP Manual explains it too and that should be any PHP developers first location too look for anyways. But since [Ask Advice](http://stackoverflow.com/questions/ask-advice) asks people to use the SO search only and searching for operators does not properly work there, I still find the downvote too harsh. I'd agree if this was any other blatant duplicate, but this one is not the OP's fault alone. It's the search engine. I'd say "In dubio pro reo" but have it your way. – Gordon Mar 18 '11 at 09:09
  • 1
    @Gordon I see you point and I removed my downvote. – markus Mar 18 '11 at 09:39

2 Answers2

0

It is a alternative if else construction.

You can write it also like:

if($xblgold == 1) {
    $xblgold == "Yes";
} else {
    $xblgold == "No";
}
Rene Terstegen
  • 7,911
  • 18
  • 52
  • 74
0

it´s the same as

if($xblgold == 1){
   $xblgold = "Yes";
}else{
   $xblgold = "No";
}
Van Coding
  • 24,244
  • 24
  • 88
  • 132