[thelist] iterating over two-dimensional arrays
Wesley Mason
wes at pmason.karoo.co.uk
Mon Jul 5 17:39:41 CDT 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
try:
echo '<select name="'.$foo.'">';
without $key (PHP's foreach() will handle the index for you, placing
the value from the next index into the single variable, $foo).
Also, you don't really need the for() for the second dimension, just do:
foreach ($foo2 as $foo) {
echo '<option name="'.$foo2.'">'.$foo2.'</option>';
}
echo '</select>';
HTH
- --
Wesley Aaron Mason
(1st Vamp)
Weblog from nowhere: http://1stvamp.org/
Webcomic from somewhere: http://gfbowl.com/
Public PGP/GPG Key: http://1stvamp.org/stuff/pgp
On Jul 5, 2004, at 10:43 pm, Ashley Graham wrote:
>> 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?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
iD8DBQFA6diyeOBnpCO+fW8RAkA0AJ9sGG68KThx2ekJhLLJ5gsyvgGY8QCgiLmg
VH8JW2+5CHVB9ewpeUScmhA=
=D5AC
-----END PGP SIGNATURE-----
More information about the thelist
mailing list