note 21039 added to ref.variables
| From: | thphp at definitynet dot com | Date: | Fri, 26 Apr 2002 09:12:38 +0000 |
| Subject: | note 21039 added to ref.variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-29866@lists.php.net to get a copy of this message | ||
Show me the vars! - Recursive Function (PHP 4 >= 4.0.4)
I hope this helps someone... I stumbled across get_defined_vars() tonight and its already making my
life easier!
I wrote this function to dump my vars for testing/debugging. Prior to this, I was walking
(list/each) through each type of global array (i.e. $_REQUEST, $_POST, $_SESSION, etc...) and
showing local vars as needed. Now this baby takes care of the lot.
Now, I tag this on the bottom of my standard footer during testing... Alas my life is MUCH easier.
Note: I Added the $depthlimit var as a limit to how many arrays it would Recursively go through...
Its probably not needed in most cases unless you have several multidimensional arrays that you want
to look at separately.
Anyway, use it as you may:
--------------------------------------------------------------
<?php
// Show ALL Variables - And I mean ALL
function showArr($xarray, $depthlimit) {
while (list($var, $value) = each($xarray)) {
if(is_array($value) && depthlimit >= 0) {
echo "<b>Array: $var</b> ($depthlimit) <blockquote>
<hr align='left' width='300'>";
$f_varcnt += showArr($xarray[$var], $depthlimit-1);
echo "<hr align='left' width='300'> </blockquote>
<b>END Array: $var</b> <br />";
} else {
echo "$var = $value<br />";
$f_varcnt++;
}
} return $f_varcnt;
}
$zz_allarr = get_defined_vars();
$zz_allvarcount = showArr($zz_allarr, 1);
echo "<hr>
<div align='center' STYLE='font-size: 14pt; font-weight: bold; color:
#021EFB;'> A total of $zz_allvarcount vars displayed.
</div>
<hr>";
?>
--------------------------------------------------------------
(sorry about the formatting of the above - The html display makes it look a little funky - but it
should work!)
Hope it helps!
Good luck!
Tedd
--
http://www.php.net/manual/en/ref.variables.php
http://master.php.net/manage/user-notes.php?action=edit+21039
http://master.php.net/manage/user-notes.php?action=delete+21039
http://master.php.net/manage/user-notes.php?action=reject+21039