FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » illegal offset problem
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: illegal offset problem [message #184055 is a reply to message #184050] Tue, 03 December 2013 23:46 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On Tue, 03 Dec 2013 17:25:49 -0500, richard wrote:

> foreach ($six0 as $itemkey => $item) {
> $song=$six0[$itemkey]['track'];
> echo "<div>$song</div>";};
>
> works fine. shows all songs for every year.
>
> }
>
> foreach ($six0 as $itemkey => $item) {
> $song=$six0[$itemkey]['track'];
> if ($year==$show){ echo "<div>$song</div>";}
> }
>
> Show nothing. Why?
>
> http://mroldies.net/test/menu4.html

I'm absolutely guessing on this one, but maybe in the second case $year
isn't equal to $show

Try dumping $show and $year

I suspect the code would be more efficient as:

if ($year==$show)
foreach ($six0 as $item)
echo "<div>{$item['track']}</div>";

1) Your code is checking $year against $show on every iteration of the
foreach loop, although neither of these variables is altered inside the
loop. Under these conditions, it makes more sense to do the comparison
outside the loop, and skip the whole loop if they don't match.

2) Having allocated the array data to $item, it is probably more
efficient to use it directly than to reference it as $six0[$itemkey],
which requires an array lookup.

I'm sure you will dismiss these points as pedantry, but pedantry such as
this equates to money in the real world of sizing server farms for the
server load.

Also, how many times do we have to point out to you that giving us links
to the output of the script doesn't really help us work out what you
screwed up.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Can I download file with address like this "http://***.com/file.php/ABC.html" automatically ?
Next Topic: request for error checking feature
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 15:02:31 GMT 2024

Total time taken to generate the page: 0.04030 seconds