Reply
in_array - what is this sample code doing
Old 05-11-2008, 12:33 AM in_array - what is this sample code doing
Novice Talker

Posts: 12
At the end of the in_array statement below what is this- ? $orderdir: "ASC"
Is this the default behavior if $orderdir evaluates to false

Code:
(in_array($orderdir, array("ASC", "DESC")) ? $orderdir : "ASC");
feelice is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-11-2008, 02:30 AM Re: in_array - what is this sample code doing
addonchat's Avatar
Skilled Talker

Posts: 97
Name: Chris Duerr
That is the ternary operator, it is somewhat equivalent to an if-then-else statement.

Basically that code is saying that if $orderdir is contained within the array("ASC", "DESC") then return $orderdir; otherwise default to return the value "ASC". The result is a string. To give you an idea as to it's logic, it's roughly equivalent to:
PHP Code:
{
   if(
in_array($orderdir, array("ASC""DESC")) 
      return 
$orderdir;
   else
      return 
"ASC";

References:
http://us3.php.net/manual/en/languag...arison.ternary
http://us2.php.net/in_array
__________________
Chris Duerr
AddonChat Java Chat Software
http://www.addonchat.com/ - Affiliate Program
addonchat is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to in_array - what is this sample code doing
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11569 seconds with 13 queries