Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

help me read this line of shorthand

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

help me read this line of shorthand

Postby iambobsmiley » Mon Mar 24, 2014 6:35 am

Hey guys,

I am new to php developing but so far have been able to do whatever I want. I recently came across a strange syntax of writing a return statement:

Code: Select all
   public static function return_taxonomy_field_value( $value )
   {
      
      return (! empty(self::$settings['tax_value']) ) ? self::$settings['tax_value'] : $value;
   }


I get the return() and the !empty() but after that it has a ? and that's where I get lost. Any help is much appreciated! Thanks guys
iambobsmiley
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Mar 24, 2014 6:32 am

Re: help me read this line of shorthand

Postby seandisanti » Sat Mar 29, 2014 6:14 pm

that's whats called a ternary comparison. a boolean expression is evaluated and different responses are given depending on whether it's true or false.
in this case, the objects tax value which is stored in the settings is evaluated to make sure that it has a value greater than 0. if it doesn, that value is returned otherwise the value stored in $value is returned instead.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron