Bhagwat Singh

PHP Developer Portfolio

PHP Shorthand If/Else Using Ternary Operators

An essential part of programming is evaluating conditions using if/else and switch/case statements. If / Else statements are easy to code and global to all languages. If / Else statements are great but they can be too long.

here is the shorthand method for this problem. it is called “Ternary operator logic”.


"(condition) ? (true return value) : (false return value)"

Example:
$bResult = ($iVar> 7 ? true : false);

This entry was posted in PHP. Bookmark the permalink.

Site Nevigation