[nycphp-talk] What are ? and :
Nunez, Eddy
enunez at tiaa-cref.org
Fri Sep 30 13:04:38 EDT 2005
Yeah no kidding .. I love this stuff!!
I've used them in sequence to test and update a conditional variable...
some actual code I wrie to set a string based on various database variables..
$approval_status = ( $adt=$res[APPROVED] ) ? "Approved on $adt" : 'Unapproved' ;
$approval_status = ( in_array($suffix,array('AN','SP')) ) ? 'N/A' : $approval_status ;
$approval_status = ( $cdt=$res[COMPLETED] ) ? "Closed on $cdt" : $approval_status ;
$approval_status = ( $cdt=$res[CANCELED] ) ? "Canceled on $cdt" : $approval_status ;
I realized in the above the sequence of the instructions is critical for the correct
result because the following statements will use the previous results on false condition.
FYI: texts refer to it as Trinary operator because it takes 3 operands, instead of
the more common 2 ops.
Cool stuff!
-----Original Message-----
From: talk-bounces at lists.nyphp.org
[mailto:talk-bounces at lists.nyphp.org]On Behalf Of Rahmin Pavlovic
Sent: Friday, September 30, 2005 12:47 PM
To: NYPHP Talk; Aaron Fischer
Subject: Re: [nycphp-talk] What are ? and :
On Fri, 30 Sep 2005 12:36 , Aaron Fischer <agfische at email.smith.edu> sent:
>I am in the process of reading through the PHundamentals article titled
>"Functions for Storing Data Submitted From a Form and Displaying Data
>from a Database" and have run into two symbols that I am unclear about
>in the fix_magic_quotes function.
>http://www.nyphp.org/phundamentals/storingretrieving.php
>
>The symbols in question are ? and :
>
>The lines where they are used:
>
>1) $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : NULL;
>
It's a conditional operator, and it's basically a simple if/else assignment. In
this case, it's checking to see if there are any arguments -- if so, they get
assigned to $argv, if not, $argv is NULL.
A lot of people don't like conditional operators, but I use them a lot.
_______________________________________________
New York PHP Talk Mailing List
AMP Technology
Supporting Apache, MySQL and PHP
http://lists.nyphp.org/mailman/listinfo/talk
http://www.nyphp.org
**************************************************************
This message, including any attachments, contains confidential information intended for a specific individual and purpose, and is protected by law. If you are not the intended recipient, please contact sender immediately by reply e-mail and destroy all copies. You are hereby notified that any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited.
TIAA-CREF
**************************************************************
More information about the talk
mailing list