Search code examples
phpif-statementternary

how to, if statement not being understood by php?


i have a if statement, and i can write it in 2 ways:

1.  echo $danceInfo->getSearchingGigDes() ? $danceInfo : 'n/a';

or

2.  if ($danceInfo){ echo $danceInfo->getSearching(); }else{ echo 'n/a'; }

the first one doesnt seem to work, and i dont understand why ??!!

i've also tryed:

1.  echo $danceInfo->getSearchingGigDes() ? isset($danceInfo) : 'n/a';

but it doesn't work as well.

any ideas?

..i mean, i could use the 2'nd option but im curious on why it doesn't work.

thanks


Solution

  • The first one should be

    echo $danceInfo ? $danceInfo->getSearchingGigDes() : 'n/a';