On Wed, April 6, 2005 1:47 am, William Stokes said:
> I need to test if a variable value is 3 or 6 or 9 or 12 or 15 or 18 ...
> goes
> on like this.
>
> How this can be done?
To be pedantic, in addition to using % (modulus) operator, you'd want to
check:
$x > 0
in order to rule out 0, -3, -6, -9
> I need to test if a variable value is 3 or 6 or 9 or 12 or 15 or 18 ... goes
if ($variable%3 == 0) #do something
--
Lars B. Jensen, Internet Architect
CareerCross Japan
Japan's premier online career resource for english speaking professionals
http://www.careercross.com
> -Original Message-
> From: William Stokes [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, April 06, 2005 10:48 AM
> I need to test if a variable value is 3 or 6 or 9 or 12 or 15 or 18
...
> goes
> on like this.
>
> How this can be done?
Have a look at modulus:
http://dk.php.net/manual/e
William Stokes wrote:
Hello,
I need to test if a variable value is 3 or 6 or 9 or 12 or 15 or 18 ... goes
on like this.
How this can be done?
if ($var % 3 == 0) { echo $var." is divisible by 3"; }
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.ph
On Wednesday 06 April 2005 10:47, William Stokes wrote:
> Hello,
>
> I need to test if a variable value is 3 or 6 or 9 or 12 or 15 or 18 ...
> goes on like this.
>
> How this can be done?
>
> Thanks
> -Will
switch($yourvar)
{case 3: somestuff;
break;
case 6: somestuff;
DUH !
Thanks all !
Obviously a slight case of brain death there !
> Hi John,
>
> > Can anyone tell me why this doesn't seem to work ??
>
> It probably is working, but it's obviously not doing what you want :-)
>
> > if (($stelle_who != '1') OR ($stelle_who != '2') OR
> > ($stelle_who != '3')
Oooops -- forgot to mention -- you might want AND not OR or ||... and some
other posts have hinted that OR does work...
Justin
on 18/12/02 12:30 AM, Justin French ([EMAIL PROTECTED]) wrote:
> Not sure if 'OR' works... I use a double pipe/vertical bar ('||') for 'OR'
>
> $stelle_who = '4';
> i
Not sure if 'OR' works... I use a double pipe/vertical bar ('||') for 'OR'
Jus to point out the really obvious... in the above example, the following
would also work:
Cheers,
Justin
on 18/12/02 12:04 AM, John Fishworld ([EMAIL PROTECTED]) wrote:
> Help !
>
> Can anyone tell me why this
Hi John,
> Can anyone tell me why this doesn't seem to work ??
It probably is working, but it's obviously not doing what you want :-)
> if (($stelle_who != '1') OR ($stelle_who != '2') OR
> ($stelle_who != '3') OR ($stelle_who != '5') ) {
This will always evaluate to true:
if $stelle_who
On Tuesday 17 December 2002 21:04, John Fishworld wrote:
> Help !
>
> Can anyone tell me why this doesn't seem to work ??
_HOW_ does it not work?
> if (($stelle_who != '1') OR ($stelle_who != '2') OR ($stelle_who != '3') OR
> ($stelle_who != '5') ) {
>
> and what can i use as an alternative synte
10 matches
Mail list logo