|
Posted by Curtis on 02/01/07 04:07
On Wed, 31 Jan 2007 17:35:25 -0800, Rik <luiheidsgoeroe@hotmail.com> wro=
te:
> Uleric <Uleric@gmail.com> wrote:
>
>> 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 !=3D=3D ("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 !=3D=3D "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 !=3D=3D ("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 !=3D=3D "here" ||
> $myzone =3D=3D "there" ||
> $myzone =3D=3D "where"){ die: }
>
> Then again, I don't understand you logic. The script is only allowed t=
o =
> run when it's 'here', so why exactly fo you want to check the rest? If=
=
> $myzone =3D=3D 'here', it cannot be anything else, unless your trying =
=
> something more complex then the example offcourse, in which case I'd b=
e =
> 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 =3D=3D 'there' || $myzone =3D=3D 'where') die;
Concerning the logic, $myzone !=3D=3D 'here' is not even needed, because=
if =
$myzone equals 'there' or 'where' it can't be 'here'. I agree, though, i=
t =
seems like the OP is actually doing something more complex. Also, only t=
he =
first boolean comparison checks against type, which seems unnecessary he=
re.
-- =
Curtis, http://dyersweb.com
Navigation:
[Reply to this message]
|