[Wylug-help] PHP foreach help
Gary Stainburn
gary.stainburn at ringways.co.uk
Thu Nov 19 15:02:16 UTC 2009
On Thursday 19 November 2009 14:38:31 William F. McCaw wrote:
> Hi Gary,
>
> On Thursday 19 November 2009 13:33:54 Gary Stainburn wrote:
> > According to the doc's, referencing $dets in the first loop should make
> > any changes made there appear in the second loop, i.e.
> >
> > foreach ($List as &$dets) {
> > if ($dets['current'] == 't') { $dets['tab']='live';}
> > if ($dets['current'] == 'f') { $dets['tab']='dead';}
> > ....
> > } # foreach
> > .....
> > .....
> > foreach ($List as &$dets){
> > if ($User['defaults']['ff_tab'] == $dets['tab'] &&
> > !isset($dets['seen'])) { paint_line($dets);
> > $dets['seen']=1;
> > }
> > }
> >
> > However, I'm getting
> >
> > PHP Notice: Undefined index: tab in /home/httpd/webroot/funding1.html
> > on line 88,
> >
> > Line 88 is the if statement inside the second look.
> >
> > Can anyone see what I've done wrong.
>
> The referencing should work, however, prior to the code shown above, can
> the array entries being referenced as "$dets['current']" be set to anything
> other than 't' or 'f', or should "$dets['tab']" be being initalized to some
> default value elsewhere, since it looks as though "$dets['tab']" isn't
> always being set.
>
> Hope this helps.
>
> WFM.
Hi William,
I have simplified the code here, but I have tried setting
$dets['tab']='';
before the if statements, and also put an error_log immediately after the two
if statements. every row does have a valid value in $dets['tab'] before the
end of the itteration in the first look.
Gary
--
Gary Stainburn
Gary's Haircut 700
Please visit http://www.justgiving.com/Gary-Stainburn/ to help me
raise money for Cancer Research - in return I'll have my head shaved
More information about the Wylug-help
mailing list