PHP Ternary Operator for If Else

These two snippets of PHP perform the same function but the ternary operator takes much less space. Read more great PHP tips at phpro.org

/*** using if / else ***/
if(isset($variable))
{
echo $variable;
}
else
{
echo '';
}

/*** using ternary ***/
echo isset($variable) ? $variable : '';

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>