Bluehost.com Web Hosting $6.95

One variable not equal to 2 values.

This is a discussion on One variable not equal to 2 values. within the PHP General forums, part of the PHP Programming Forums category; How would I write this statement: if $thisvar is not equal to this value or that value. { do stuff } Thanks, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-25-2003
Ed Curtis
 
Posts: n/a
Default One variable not equal to 2 values.


How would I write this statement:

if $thisvar is not equal to this value or that value. { do stuff }


Thanks,

Ed
Reply With Quote
  #2 (permalink)  
Old 09-25-2003
Cesar Cordovez
 
Posts: n/a
Default Re: [PHP] One variable not equal to 2 values.

Other way to do it is:

$posible_values = array("this value", "that value", "other value");
if (in_array($thisvalue, $posible_values)) {
// $thisvalue is in $posible_values
} else {
// $thisvalue is NOT in $posible_values
}

Cesar

I wrote:

> <corection to last post>But then... you have to use "and" not "or"
> like:</corection to last post>
>
> if (($thisvar != "this value") and ($thisvar != "thatvalue")) {
> // do stuff
> }
>
> Cesar Cordovez wrote:
>
>> if (($thisvar != "this value") or ($thisvar != "thatvalue")) {
>> // do stuff
>> }
>>
>> cesar =)
>>
>> Ed Curtis wrote:
>>
>>> How would I write this statement:
>>>
>>> if $thisvar is not equal to this value or that value. { do stuff }
>>>
>>>
>>> Thanks,
>>>
>>> Ed
>>>

>>

>

Reply With Quote
  #3 (permalink)  
Old 09-26-2003
Robert Cummings
 
Posts: n/a
Default Re: [PHP] One variable not equal to 2 values.


On Thu, 2003-09-25 at 19:49, Curt Zirzow wrote:
> * Thus wrote Ed Curtis (ed@homes2see.com):
> >
> > How would I write this statement:
> >
> > if $thisvar is not equal to this value or that value. { do stuff }
> >

>
> Ok. I have to throw this in for historical purposes :)
>
> switch ($thisvar) {
> case 'thisvalue':
> case 'thatvalue':
> break;
> default:
> // do stuff
> break;
> }


*grin* here's another:

if( $thisvar == 'this value'
? false
: ($thisvar == 'that value'
? false
: true) )
{
// do stuff.
}

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. |
`------------------------------------------------------------'
Reply With Quote
  #4 (permalink)  
Old 09-26-2003
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] One variable not equal to 2 values.

* Thus wrote Ed Curtis (ed@homes2see.com):
>
> How would I write this statement:
>
> if $thisvar is not equal to this value or that value. { do stuff }
>


Ok. I have to throw this in for historical purposes :)

switch ($thisvar) {
case 'thisvalue':
case 'thatvalue':
break;
default:
// do stuff
break;
}



Curt
--
"I used to think I was indecisive, but now I'm not so sure."
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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




All times are GMT +1. The time now is 02:13 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0