Re: [PHP] IF with multiple values for a variable
Robert Cummings wrote: > On Thu, 2007-06-14 at 12:12 +0200, Jochem Maas wrote: >> Robert Cummings wrote: >>> On Wed, 2007-06-13 at 13:57 -0400, [EMAIL PROTECTED] wrote: double pipes constitutes an "OR" operation. You can use the keyword OR as well. Also, && and AND are the same as well. http://us.php.net/manual/en/language.operators.logical.php >>> They aren't exactly the same. Make sure and read the order of precedence >>> note. The following, for example, are not equivalent: ... >> >> thanks to Robbert for the brainteaser ;-) > ^^^ > I'm not sure if you're confused, pulling my leg, or somehow capable of > slurring a 'b' :) either the first or the last - choose one. at this point I think it best that we start one of those pointless, neverending threads about 'Personal Name' normalization. ucfirst('trebor'); :-P > > Cheers, > Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IF with multiple values for a variable
On Thu, 2007-06-14 at 12:12 +0200, Jochem Maas wrote: > Robert Cummings wrote: > > On Wed, 2007-06-13 at 13:57 -0400, [EMAIL PROTECTED] wrote: > >> double pipes constitutes an "OR" operation. You can use the keyword OR > >> as well. Also, && and AND are the same as well. > >> > >> http://us.php.net/manual/en/language.operators.logical.php > > > > They aren't exactly the same. Make sure and read the order of precedence > > note. The following, for example, are not equivalent: > > I knew that they we're not exactly the same due to order of precedence, but > I ran Robbert's code snippet and found that my assumptions about the outcome > incorrect! ^^^ That's Robert :) > my assumption was that '=' had lower precedence that 'and' ... somehow that > felt right, > obviously I was wrong. > > it took me a few seconds to see the error of my ways :-) maybe there are other > that are confused ... maybe the output of following little snippet might help > to clarify: > > > $true = true; > $false = false; > > $test1 = $true && $false; > $test5 = ($test2 = $true and $false); > $test3 = ($true && $false); > $test4 = ($true and $false); > > var_dump($test1, $test2, $test3, $test4, $test5); > > ?> > > thanks to Robbert for the brainteaser ;-) ^^^ I'm not sure if you're confused, pulling my leg, or somehow capable of slurring a 'b' :) Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IF with multiple values for a variable
Robert Cummings wrote: > On Wed, 2007-06-13 at 13:57 -0400, [EMAIL PROTECTED] wrote: >> double pipes constitutes an "OR" operation. You can use the keyword OR as >> well. Also, && and AND are the same as well. >> >> http://us.php.net/manual/en/language.operators.logical.php > > They aren't exactly the same. Make sure and read the order of precedence > note. The following, for example, are not equivalent: I knew that they we're not exactly the same due to order of precedence, but I ran Robbert's code snippet and found that my assumptions about the outcome incorrect! my assumption was that '=' had lower precedence that 'and' ... somehow that felt right, obviously I was wrong. it took me a few seconds to see the error of my ways :-) maybe there are other that are confused ... maybe the output of following little snippet might help to clarify: thanks to Robbert for the brainteaser ;-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IF with multiple values for a variable
Dan Shirah wrote: if ($type == 'T','D','L' { $get_id.=" payment_request WHERE id = '$payment_id'"; } if (in_array($type, array('T', 'D', 'L'))) { ... } -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IF with multiple values for a variable
On Wed, June 13, 2007 12:35 pm, Dan Shirah wrote: > Okay, I know this has got to be easy but it's not working any way I > try it. > > When a record is selected it opens up a new page. My query will > display the > specific results based on the type of record selected. There can be > multiple values in each if. However I am having a brain fart in my if > statement assigning the multiple values. > > Here is my if statement: > > if ($type == 'T','D','L' { //this will work: if ($type == 'T' || $type == 'D' || $type == 'L'){ > $get_id.=" payment_request WHERE id = '$payment_id'"; > } -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IF with multiple values for a variable
On Wed, 2007-06-13 at 13:57 -0400, [EMAIL PROTECTED] wrote: > double pipes constitutes an "OR" operation. You can use the keyword OR as > well. Also, && and AND are the same as well. > > http://us.php.net/manual/en/language.operators.logical.php They aren't exactly the same. Make sure and read the order of precedence note. The following, for example, are not equivalent: Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IF with multiple values for a variable
double pipes constitutes an "OR" operation. You can use the keyword OR as well. Also, && and AND are the same as well. http://us.php.net/manual/en/language.operators.logical.php -TG = = = Original message = = = Excellent! Double pipes to seperate possible multiple variable values. Thanks Daniel! On 6/13/07, Daniel Brown <[EMAIL PROTECTED]> wrote: > > On 6/13/07, Dan Shirah <[EMAIL PROTECTED]> wrote: > > Okay, I know this has got to be easy but it's not working any way I try > it. > > > > When a record is selected it opens up a new page. My query will display > the > > specific results based on the type of record selected. There can be > > multiple values in each if. However I am having a brain fart in my if > > statement assigning the multiple values. > > > > Here is my if statement: > > > > if ($type == 'T','D','L' > > $get_id.=" payment_request WHERE id = '$payment_id'"; > > > > > > However this does not return ant results. > > I've tried if ($type = array('T','D','L'), if ($type == > array('T','D','L'), > > if ($type == 'T,D,L'), if ($type == 'T' or 'D' or 'L' > > > > I also looked in the PHP manual for examples of if's and didn't find any > > help. > > > > I can get it to work if I create a seperate if statement for each type > > condition but i would prefer to not duplicate my code just to add a > seperate > > $type > > > >Dan, > >Are you trying to do this? > > if ($type == 'T' || $type == 'D' || $type == 'L') >$get_id.=" payment_request WHERE id = '$payment_id'"; > > ?> > > -- > Daniel P. Brown > [office] (570-) 587-7080 Ext. 272 > [mobile] (570-) 766-8107 > ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IF with multiple values for a variable
Could try something like this: $types = array('T', 'D', 'L'); if (in_array($type, $types)) { // do something } But that's going to just check to see if $type is one of the valid types you're looking for. You might try something like switch. switch ($type) { case 'T': // Output 'T' record type break; case 'D': // Output 'D' record type break; case 'L': // Output 'L' record type break; default: break; } "switch" works really well when you have multiple "if" scenarios and don't want to keep doing a ton of if.. elseif... elseif...elseif... for simple comparisons. You can even use it for more complicated comparisons: switch (true) { case $type == 'T': break; case $type == 'D' and $flavor <> 'grape': break; default; break; } the "default" section is what's processed if no critera are met. Also, if you want to use the same criteria for multiple conditions, or slight variations, you can do that by removing 'break' codes: switch ($type) { case 'T': case 'D': // Do something if $type is either T or D break; case 'L': // Do something L specific case 'R': // Do something if $type is L or R (passes through from L condition because break was removed) break; default: break; } More reading here: http://us.php.net/switch Hope that helps. -TG = = = Original message = = = Okay, I know this has got to be easy but it's not working any way I try it. When a record is selected it opens up a new page. My query will display the specific results based on the type of record selected. There can be multiple values in each if. However I am having a brain fart in my if statement assigning the multiple values. Here is my if statement: if ($type == 'T','D','L' $get_id.=" payment_request WHERE id = '$payment_id'"; However this does not return ant results. I've tried if ($type = array('T','D','L'), if ($type == array('T','D','L'), if ($type == 'T,D,L'), if ($type == 'T' or 'D' or 'L' I also looked in the PHP manual for examples of if's and didn't find any help. I can get it to work if I create a seperate if statement for each type condition but i would prefer to not duplicate my code just to add a seperate $type ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IF with multiple values for a variable
Excellent! Double pipes to seperate possible multiple variable values. Thanks Daniel! On 6/13/07, Daniel Brown <[EMAIL PROTECTED]> wrote: On 6/13/07, Dan Shirah <[EMAIL PROTECTED]> wrote: > Okay, I know this has got to be easy but it's not working any way I try it. > > When a record is selected it opens up a new page. My query will display the > specific results based on the type of record selected. There can be > multiple values in each if. However I am having a brain fart in my if > statement assigning the multiple values. > > Here is my if statement: > > if ($type == 'T','D','L' { > $get_id.=" payment_request WHERE id = '$payment_id'"; > } > > However this does not return ant results. > I've tried if ($type = array('T','D','L'), if ($type == array('T','D','L'), > if ($type == 'T,D,L'), if ($type == 'T' or 'D' or 'L' > > I also looked in the PHP manual for examples of if's and didn't find any > help. > > I can get it to work if I create a seperate if statement for each type > condition but i would prefer to not duplicate my code just to add a seperate > $type > Dan, Are you trying to do this? -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107
Re: [PHP] IF with multiple values for a variable
On 6/13/07, Dan Shirah <[EMAIL PROTECTED]> wrote: Okay, I know this has got to be easy but it's not working any way I try it. When a record is selected it opens up a new page. My query will display the specific results based on the type of record selected. There can be multiple values in each if. However I am having a brain fart in my if statement assigning the multiple values. Here is my if statement: if ($type == 'T','D','L' { $get_id.=" payment_request WHERE id = '$payment_id'"; } However this does not return ant results. I've tried if ($type = array('T','D','L'), if ($type == array('T','D','L'), if ($type == 'T,D,L'), if ($type == 'T' or 'D' or 'L' I also looked in the PHP manual for examples of if's and didn't find any help. I can get it to work if I create a seperate if statement for each type condition but i would prefer to not duplicate my code just to add a seperate $type Dan, Are you trying to do this? -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php