[thelist] iterating over two-dimensional arrays
Seyon
evoltlist at delime.com
Mon Jul 5 17:39:44 CDT 2004
Message from Ashley Graham (7/5/2004 05:43 PM)
>>foreach ($styles as $foo) // iterates through each set of sub-arrays in
>>the array
>>{
>> echo <select name="$foo[$key];
>> $arraylen = count($foo); // checks size of the current sub-array
>> for($i = 0; $i < $arraylen; $i++)
>> { // iterates through each entry within the sub-array
>> echo <option name="$foo[$i]">$foo[$i]</option> // writes your
>> option statement
>> }
>> echo </select>;
>>}
>
>I can't seem to get the
>
>>echo <select name="$foo[$key];
>
>to echo anything--I've modified it so that it runs, adding the needed
>quotation marks and everything. I don't get any errors, it simple echoes
>nothing.
>
>Any suggestions?
Change the first statement to
foreach ($styles as $key=>$foo)
$key will now contain the name of the key.
Then
echo <select name="$key">;
That should work without any further modifications to the code.
>On another note the rest of it works like a charm.
There's something I don't hear every day. ;-)
regards.
-marc
--
Trinidad Carnival in all its photographic glory. Playyuhself.com
http://www.playyuhself.com/
More information about the thelist
mailing list