-3

Please look at my code...

$sample = 'done';

$sample1 = 'welcome';

echo isset($sample) ? $sample : isset($sample1) ? $sample1 : '';

this will returns as welcome. But how variable $sample is present in this sense result would be done .. kindly help me?

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
Jagadeesh
  • 734
  • 6
  • 26

2 Answers2

3

I suspect this is a problem with the order of operations in your last line. This is, in a word, confusing:

isset($sample) ? $sample : isset($sample1) ? $sample1 : '';

If you want separate conditional clauses, explicitly separate them with parentheses:

isset($sample) ? $sample : (isset($sample1) ? $sample1 : '');

Otherwise I suspect everything before the second conditional statement is collectively evaluating to true and thus outputting $sample1.

David
  • 208,112
  • 36
  • 198
  • 279
0
$sample = 'done';

$sample1 = 'welcome';

echo isset($sample) ? $sample : isset($sample) ? $sample : '';

You're missing a $ in front of sample1 =

Jesper
  • 3,816
  • 2
  • 16
  • 24