Re: GLOBALS question / print out GLOBALS

From: Date: Wed, 24 May 2000 18:25:24 +0000
Subject: Re: GLOBALS question / print out GLOBALS
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-459@lists.php.net to get a copy of this message
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

« previous php.general (#459) next »