NYCPHP Meetup

NYPHP.org

[nycphp-talk] What are ? and :

Anirudh Zala arzala at gmail.com
Sat Oct 1 00:08:07 EDT 2005


I like this stuff as well. It is very useful when editing some data that 
comes from DB, and while updating it when some conditions fails, values 
came from DB and values changed by users both can be checked and 
retained in form. Like below.

$phoneVal=isset($_POST['phone']) ? $_POST['phone'] : $someRow->phone;

However there are many use of these operators. One can use in their 
preferred way as he/she likes.

Thanks,

Anirudh Zala

----------------------------------------------------------------
Anirudh Zala (Production Manager),    ASPL, 814-815, Star Plaza,
Ph: +91 281 245 1894                  Phhulchhab Square,
anirudh at aspl.in                       Rajkot 360001, Gujarat
http://www.aspl.in                    INDIA
----------------------------------------------------------------



Nunez, Eddy wrote:

>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
>**************************************************************
>
>_______________________________________________
>New York PHP Talk Mailing List
>AMP Technology
>Supporting Apache, MySQL and PHP
>http://lists.nyphp.org/mailman/listinfo/talk
>http://www.nyphp.org
>
>  
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20051001/e2bcf3a9/attachment.html>


More information about the talk mailing list