in your php script. Call it like this: printarray($myArray);
*/
// Placing an ampersand before the variable, tells this function to access
// the array directly instead of making a copy. This is needed to get its
// actual name from the vname function.
function printarray(&$array) {
echo "
";
if (is_array($array)) { // If it's an array, show formatted key-val pairs
reset($array);
walkarray($array, vname($array), '');
}
echo "";
}
function walkarray($array, $me='', $indent='') {
$startmsg = "==== Start of '$me' Array ====";
$l = strlen($startmsg);
echo $indent.$startmsg.'
';
//echo $indent.''.str_repeat("-",$l).'
';
while (list($key, $val) = each($array)) {
echo $indent."key = '$key' => val = '$val'
";
//echo "val = $val
";
if (is_array($val)) { // If it's an array, recurse, iterate, and show it
//echo '
';
walkarray($val, $key, $indent.' ');
}
}
echo $indent."==== End of '$me' Array ====
";
//$indent = '';
}
//This function is from http://www.php.net/manual/en/language.variables.php#49997
function vname(&$var, $scope=false, $prefix='unique', $suffix='value') {
if($scope) $vals = $scope;
else $vals = $GLOBALS;
$old = $var;
$var = $new = $prefix.rand().$suffix;
$vname = FALSE;
foreach($vals as $key => $val) {
if($val === $new) $vname = $key;
}
$var = $old;
return $vname;
}
?>