473,671 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple (OR ||) case usage

Having trouble wrapping this up into a viable statement

I want to check on a users status before allowing a script to be run.
$myzone can only be 1 variable, but it can be here, there or where.

if ($myzone !== ("here") or ("there") or ("where")) { die: }

This does not work however, it will kill the script regardless if one
of the statments is actually true.

However, this WILL work if only one operator is checked:

if ($myzone !== "here") { die: }

If $myzone is "here" the script is allowed to run. If it's anything
else, it dies, as it is supposed to. However, I want to check if
$myzone is several options. That is my delima.

Feb 1 '07 #1
3 1335
Rik
Uleric <Ul****@gmail.c omwrote:
Having trouble wrapping this up into a viable statement

I want to check on a users status before allowing a script to be run.
$myzone can only be 1 variable, but it can be here, there or where.

if ($myzone !== ("here") or ("there") or ("where")) { die: }

This does not work however, it will kill the script regardless if one
of the statments is actually true.

However, this WILL work if only one operator is checked:

if ($myzone !== "here") { die: }

If $myzone is "here" the script is allowed to run. If it's anything
else, it dies, as it is supposed to. However, I want to check if
$myzone is several options. That is my delima.
Unfortunately, this is not how conditionals work.
You first statement breaks down like:
$myzone !== ("here") -can be true or false
or
("there") -a string, which cast to a boolean will always be true, no
further evaluation will be done, conditions are met, code die()s .

You could use a lengthy version:
if (
$myzone !== "here" ||
$myzone == "there" ||
$myzone == "where"){ die: }

Then again, I don't understand you logic. The script is only allowed to
run when it's 'here', so why exactly fo you want to check the rest? If
$myzone == 'here', it cannot be anything else, unless your trying
something more complex then the example offcourse, in which case I'd be
interested in what exactly.
--
Rik Wasmus
Feb 1 '07 #2
On Wed, 31 Jan 2007 17:35:25 -0800, Rik <lu************ @hotmail.comwro te:
Uleric <Ul****@gmail.c omwrote:
>Having trouble wrapping this up into a viable statement

I want to check on a users status before allowing a script to be run.
$myzone can only be 1 variable, but it can be here, there or where.

if ($myzone !== ("here") or ("there") or ("where")) { die: }

This does not work however, it will kill the script regardless if one
of the statments is actually true.

However, this WILL work if only one operator is checked:

if ($myzone !== "here") { die: }

If $myzone is "here" the script is allowed to run. If it's anything
else, it dies, as it is supposed to. However, I want to check if
$myzone is several options. That is my delima.

Unfortunately, this is not how conditionals work.
You first statement breaks down like:
$myzone !== ("here") -can be true or false
or
("there") -a string, which cast to a boolean will always be true, no
further evaluation will be done, conditions are met, code die()s .

You could use a lengthy version:
if (
$myzone !== "here" ||
$myzone == "there" ||
$myzone == "where"){ die: }

Then again, I don't understand you logic. The script is only allowed to
run when it's 'here', so why exactly fo you want to check the rest? If
$myzone == 'here', it cannot be anything else, unless your trying
something more complex then the example offcourse, in which case I'd be
interested in what exactly.
There is an error in both snippets of code "die:" is used, you need end
the statement with a semi-colon ";"

if ($myzone == 'there' || $myzone == 'where') die;

Concerning the logic, $myzone !== 'here' is not even needed, becauseif
$myzone equals 'there' or 'where' it can't be 'here'. I agree, though, it
seems like the OP is actually doing something more complex. Also, only the
first boolean comparison checks against type, which seems unnecessary here.

--
Curtis, http://dyersweb.com
Feb 1 '07 #3
Uleric wrote:
if ($myzone !== ("here") or ("there") or ("where")) { die: }
Try:

if ($myzone!='here ' && $myzone!='there ' && $myzone!='where ') die;
Or, using De Morgan's Laws (boolean algebra law concerning the
relationship between NOT, AND and OR) you could alternatively use:

if (!( $myzone=='here' || $myzone=='there ' || $myzone=='where ' )) die;
Or, to make your code read a bit more sanely (but might actually run
slower!):

$allowed_states = array('here', 'there', 'where');
if (!in_array($myz one, $allowed_states )) die;
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Feb 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8609
by: Phil Powell | last post by:
Has anyone here ever done a case where you have a select multiple form element and you have to do both server-side and client-side validation? I am honestly not sure how to do it in Javascript (I keep getting errors thrown that I can't verify because the form processes onto itself too quickly for me to check the Javascript errors) because the select multiple form element name has to be in the form of "var" because PHP will then recognize...
66
4979
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
39
2890
by: Scotter | last post by:
Okay I think my title line was worded misleadingly. So here goes again. I've got quite 20 identical MDB files running on an IIS5 server. From time to time I need to go into various tables and add a field or two. It would be great if there were an application out there that could either: (a) sync all MDB designs (and/or data) designated to match one I've added some fields/tables to OR (b) go into all designated MDBs and create new...
4
2396
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a hierarchy of algebraic matrices with the addition operation. Thus, I want to have a virtual base class class Matr;
1
2937
by: Niels Dekker - no reply address | last post by:
The book "C++ Coding Standards" by Herb Sutter and Andrei Alexandrescu warns against potential memory leaks when having multiple calls to operator new within a single statement. (Item 13, page 25.) These leaks would still be there when wrapping the result of each "new" in a temporary smart pointer object. Is there a simular risk when having multiple calls to new in member initializer list of a constructor? For example: class Foo
11
4652
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m having a heck of a time doing so. I have created a form where I use drop downs do specify year, month, date, hour, minute and seconds. When the form is loaded, the dropdowns have to display the proper values for the current time zone type. This
22
23350
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete examples?
47
3626
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
11
4336
by: Olie | last post by:
This post is realy to get some opinions on the best way of getting fast comunication between multiple applications. I have scowered the web for imformation on this subject and have just found conflicting views and far from ideal solutions. My application has to send small amounts of data about 50bytes to multiple client applications. The catch is that this has to happen about 1000 times a second. My first attempt was .net remotting...
19
6333
by: Zytan | last post by:
I want multiple instances of the same .exe to run and share the same data. I know they all can access the same file at the same time, no problem, but I'd like to have this data in RAM, which they can all access. It seems like a needless waste of memory to make them all maintain their own copy of the same data in RAM at the same time. What's the best way to achieve this? I've heard of memory mapped files, so maybe that's the answer. ...
0
8485
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8403
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8677
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5704
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4417
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.