why does the first example work but the next one just gives me the propper
count, not the actual variable values.
example 1:
<?
$a1 = array(1, 2, 3, 4, "testing", 5);
print "a1:\n";
for($i=0,$n=count($a1); $i<$n; $i++)
{
print " $i: $a1[$i]\n";
}
?>
example 2:
<?
print "globals:\n";
for($i=0,$n=count($GLOBALS); $i<$n; $i++)
{
print " $i: "; print $GLOBALS[$i]; print "\n";
}
?>
Hello Angus,
To answer both of your questions...
The $GLOBALS array is not a numerically keyed array. There are no values assigned to the variables that you are requesting.
Here is your code with a slight modification.
<?
print '$GLOBALS ARRAY:<br><ul>';
while ( list ($key, $value) = each ($GLOBALS))
print "<b>$key:</b> $value<br>";
?>
or you could use
<PRE>
<? var_dump ($GLOBALS); ?>
or print_r instead of var_dump
HTH,
Zak