PDA

View Full Version : Need help with an Array


PcFreak
10-17-2005, 07:46 PM
I have the following Array

with print_r($output);

Array ( [Peter] => 32 [Bibo] => 4 [Lili] => 2 [Uwe] => 2 [Didi] => 1 [Freak] => 0)

with print_r(array_keys ($output));

Array ( [0] => Peter [1] => Bibo [2] => Lili [3] => Uwe [4] => Didi [5] => Freak)

with print_r(array_values ($output));

Array ( [0] => 32 [1] => 4 [2] => 2 [3] => 2 [4] => 1 [5] => 0)

I would like to have a loop for key and value variables, because i want to output this vars in a table on a html page.
e.g

$key[] = ? // Peter, Bibo, Lili etc.
$value[] = ? // 32, 4 ,2 etc

For a table like this


Key / value
__________
Peter / 32
Bibo / 4
Lili / 2


PcFreak

Andreas
10-17-2005, 08:05 PM
echo('<table>');
echo('<tr><td>Key</td><td>Value</td></tr>');
foreach ($output AS $name => $number)
{
echo("<tr><td>$name</td><td>$number</td></tr>");
}
echo('</table>');

PcFreak
10-17-2005, 08:34 PM
Jep.

Thats work.

The print_r command confused me.

Thank you very much

PcFreak