[olug] crazy php stuff

Brian Roberson roberson at olug.org
Thu Aug 7 18:34:57 UTC 2003


Thought I would pass this along to the other php'ers here..

So I whipped up this php thing a while ago.. anyways I had an array of k->v
pairs and I was using a foreach to walk through it, one k->v always gets
missed/messed up... not in the middle,start, or end, basically it is a date
padding feature... here is a snippit:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo "<SELECT NAME=DAY>";
$DD = array(
01 => 1,
02 => 2,
03 => 3,
04 => 4,
05 => 5,
06 => 6,
07 => 7,
08 => 8,
09 => 9,
10 => 10,
11 => 11,
12 => 12,
13 => 13,
14 => 14,
15 => 15,
16 => 16,
17 => 17,
18 => 18,
19 => 19,
20 => 20,
21 => 21,
22 => 22,
23 => 23,
24 => 24,
25 => 25,
26 => 26,
27 => 27,
28 => 28,
29 => 29,
30 => 30,
31 => 31,
);
foreach ($DD as $dr => $dd) {
$DAY = date("d");
if ($DAY == $dr) { $SEL = " SELECTED "; } else { $SEL = ""; }
echo "<OPTION VALUE=$dr$SEL>$dd\n";
}
echo "
</SELECT>
";


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

pretty basic eh? -- anyways.... the 8th element ALWAYS gets munged ( give it
a try, I used 3 different php vers, all above 4.1.


anyone have any ideas what the heck is happenening --- In ANY event I got
around it, in alot less lines of code, so for the intrigued, here is my
solution....


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

for( $i=1;$i <= 31;$i++ )
{
        $DAY = date("d");
        if ($DAY == $i) { $SEL = " SELECTED "; } else { $SEL = ""; }
        printf( "\t<OPTION VALUE=%02d $SEL>$i\n", $i );
}

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



It still bugs the crap out of me why it skips an element, so if anyone has
an idea, pas it along!!











More information about the OLUG mailing list