[Wylug-help] PHP foreach help
William F. McCaw
william at mcsquawk.org.uk
Thu Nov 19 14:38:38 UTC 2009
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.
--
William F. McCaw <william at mcsquawk.org.uk>
Public key available from http://www.mcsquawk.org.uk/ and keyservers
GPG : 0x34C648D9 : 2744 C1E8 38AE FC6F 38CC 1D1E F9E9 D8D2 34C6 48D9
More information about the Wylug-help
mailing list