News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Using the Ternary Operator
November 01, 2011 @ 09:43:35

On PHPMaster.com today there's a new tutorial showing the use of a sometimes overlooked (but very handy) alternate syntax that PHP includes - the ternary operator, a short-hand if/else.

You're probably already familiar with PHP's if statement. It's very similar to its counterparts in many other programming languages and represents one of the most fundamental concepts in programming. [...] But there's a way to build on this concept and increase your $coolFactor a bit in the process. Allow me to introduce you to the ternary operator, which serves as a shorthand notation for if statements.

They introduce the ternary operator's syntax, the ":" and "?" operators and includes a few pieces of code showing its use. Thankfully they also include a warning - don't overuse or abuse it...and especially don't nest them - that just leads to headaches.

0 comments voice your opinion now!
ternary if else shorthand alternate syntax


blog comments powered by Disqus

Similar Posts

Cocoliso's Blog: Adding A Syntax Highlighter To Your Site: The Power Of Geshi

Nikita Popov: How to add new (syntactic) features to PHP

PHPBuilder.com: 10 Productivity-boosting Tools for Your PHP Development

Freek Lijten's Blog: Currently on PHP's internals...

Sandro Groganz's Blog: Syntax Highlighting & Migrating Permalinks in WordPress


Community Events





Don't see your event here?
Let us know!


bugfix opinion series symfony laravel framework language package api list library tips community introduction interview podcast deployment release install voicesoftheelephpant

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework