Friday 15 April 2011

html - IF/ELSE statement inside PHP variable string -



html - IF/ELSE statement inside PHP variable string -

what right way utilize if/else statement within of variable string?

example:

$htmloutput = 'the current color of sky ' . if ($time==="day") { . 'blue.' . } else if ($time==="night") { . 'black' . };

obviously illustration not work, see i'm trying do. know go on variable within of if statement like:

$htmloutput .= '';

but i'm curious if there's way stated above.

you utilize ternary operator this

$htmloutput = 'the current color of sky ' . ($time == 'day' ? 'blue' : 'black');

php html if-statement

No comments:

Post a Comment