|
Posted by greedo on 11/26/06 17:37
First of all thanks, I will try to figure out what you did there and
hopefully this'll do. May take me a moment, tho. :)
Mladen Gogala wrote:
> On Sun, 26 Nov 2006 07:44:53 -0800, greedo wrote:
>
> > Hi, first of all, please bear with me, I don't really know a great deal
> > about php programming, as will be painfully obvious from the code
> > snippet I'm gonna post. But I need this problem solved, and I can't
> > find the information I need (or maybe I can't understand it). So here's
> > the thing:
> >
> > What I have is a range of integers, and I need those whose digits
> > alternate between odd and even. Example: 123456789. For that purpose I
> > have this thingy here:
> >
> > settype($zee, "string");
> > if (($zee[0] % 2 != 0) && ($zee[1] % 2 == 0))
> > {
> > echo $zee . "<br />";
> >
> > }
> >
> > Just to be precise: I want to have $zee echoed, if the first digit is
> > odd and the second is even.
> >
> > Now, this doesn't work, because apparently the second condition is
> > never true. I don't get why. Because if I change the "==" in the second
> > condition to "!=" (that is to say I want both digits to be odd), then
> > it works fine! Can someone help me fix this?
> >
> > PS:
> > When the conditions are put like this:
> > if (($zee[0] & 1) && ($zee[1] & 0))
> > the exact same thing happens: it works with two odd conditions, but not
> > with one odd, one even.
>
> Your type conversion is a mortal sin and may cost you dearly when you meet
> the Great Programmer. Repent, o sinner, change thy evil ways and do
> something like this:
>
> $zere="345678";
> $zee=preg_split('//',$zere,-1,PREG_SPLIT_NO_EMPTY);
> if (($zee[0] % 2 != 0) && ($zee[1] % 2 == 0))
> {
> echo "zere=$zere\n";
>
> }
> else echo '$zee[0]=',$zee[0]," ",'$zee[1]=',$zee[1],"\n";
>
>
> BTW, your assumption about C-ish equivalent between strings and arrays
> does not hold water in the PHP world. Your "settype" trick would be neat,
> had it worked.
>
> --
> http://www.mladen-gogala.com
Navigation:
[Reply to this message]
|