lundi 22 janvier 2018

IF condition shorthand in php

php syntax error when I try to echo

$v = 10;
($v==9) ? echo 'yes' :echo  'No';

show this error

syntax error, unexpected 'echo' (T_ECHO) while this is syntax correct

while I print with print keyword print correctly

$v = 10;
  ($v==10) ? print 'yes' : print 'No';

I know the right syntax of if shorthand

$v = 10;
    echo ($v==9) ? 'yes' : 'No';

the question why give error when i try with echo keyword inside the condition

Aucun commentaire:

Enregistrer un commentaire