«« Next » « Previous
«« Next » « Previous

Link Details

Announcement

iPhone DZone: Fresh Links On Your iPhone by matt at Sat Jul 05 14:09:51 EDT 2008

Reading DZone on your iPhone just got a little bit easier. Visit http://dzone.com/iphone from your iPhone to try out our beta iPhone support. You can view stories, filter by tags, and login. We'd appreciate your feedback at feedback@dzone.com.

If you don't vote, who will? Login and vote now.
Link 62764 thumbnail

By harlan
via php.dzone.com
Published: Jan 23 2008 / 13:51

In looking at my Google Analytics statistics, I see a lot of visitors searching for PHP shorthand if/else (ternary) information. I've gone through my code library and picked out some examples of ternary operator usage.
  • 14
  • 0
  • 1052
  • 374

Comments

Add your comment
User 233461 avatar

antych replied ago:

1 votes Vote down Vote up Reply

If you are showing off shorthand, you should know that
$is_admin = ($user['permissions'] == 'admin' ? true : false);
is the same as
$is_admin = ($user['permissions'] == 'admin');
== operator already returns boolean value!

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.