1

Topic: A simple question on php arrays and the foreach loop

I have a webpage of links that i want displayed under different headings, depending on which array they're in. I have 4 different arrays...

I had identical code for all of these so i thought i would write a function....
This is what I came up with:

function listlinks ($array)
    { 
        $counter = '1';
    
        foreach ($array as $key => $value) 
            {
                if($counter%2){ echo '<tr class="alt"><td>'; }else{ echo '<tr><td>'; }
                echo " » $value</a></td></tr>";
                $counter++;
            }
    }

It keeps telling me that I have an invalid arguement supplied for foreach.

Can anyone help?

Re: A simple question on php arrays and the foreach loop

Well, that means you're calling the function with a variable that is not an array for some reason.

"Programming is like sex: one mistake and you have to support it for the rest of your life."