0
How to echo all global variables only if they are in string
2 Respostas
+ 2
You can loop over the $GLOBALS variable and than check if each variable is a string, or loop again if certain super global variables are arrays. I found this on stack overflow:
I would avoid the foreach loop entirely:
<?php print_r($GLOBALS); ?>
I'm not sure of an instance where I would need to print the globals in html quite like that except for debugging.
You are probably coming up on problems in recursion of globals so you could possibly do something like:
<?php
$myGlobals = array();
foreach($GLOBALS as $key => $value ) {
if ($key == 'GLOBALS') {
continue;
} else {
$myGlobals[$key] = $value;
}
}
foreach ($myGlobals as $key => $value ) { ?>
<dt><label for="<?php echo $key ?>">$key</label></dt>
<dd><input type="text" name="<?php echo $key ?>" value="<?php echo $value ?>" /></dd>
<?php } ?>
https://stackoverflow.com/questions/28279929/printing-out-globals-using-foreach
w3schools PHP Global: https://www.w3schools.com/php/php_superglobals.asp
0
thanks