faqts : Computers : Programming : Languages : PHP : kms : General

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

10 of 10 people (100%) answered Yes
Recently 7 of 7 people (100%) answered Yes

Entry

Can I use echo inside a ternary expression?

Jun 8th, 1999 07:00
Nathan Wallace, Lars Torben Wilson


No.

This is due the fact that echo isn't a function, it's an expression.
so you can't use it precisely like that. Either of the following will
work, however:

<?php

$foo = 1;

($foo == 1) ? print "blip" : print "blop" ;

echo ( ($foo == 1) ? "blip" : "blop" );

?>