|
Posted by macca on 10/19/07 02:45
>I wonder in PHP, can you have a function like
> print_debug($foo);
>and it will print out:
>$foo is:
>3
<?php
//============ Function : print_debug( arr result of get_defined_vars,
mixed variable to debug)
function print_debug($defined_vars_array, $debug){
$unset_unwanted =
array("GLOBALS","_POST","_GET","_COOKIE","_FILES");
foreach ($unset_unwanted as $remove){
unset($defined_vars_array[$remove]);
}
while ($element = current($defined_vars_array)) {
if ($element == $debug) {
if (is_array($debug)){
echo '$'.key($defined_vars_array).' = <br />'.
print_r($debug, TRUE) . "<br />";
} else {
echo '$'.key($defined_vars_array).' = '. $debug . "<br />";
}
}
next($defined_vars_array);
}
}
//============= End of Function
//=========================================
// somescript.php
// Test Variable
$test_var1 = "This is a test Variable";
$var_test = array(1,2,3);
// debug the variable by calling "print_debug()"
$arr = get_defined_vars();
print_debug($arr,$var_test);
?>
Prints
$var_test =
Array ( [0] => 1 [1] => 2 [2] => 3 )
You get the point. Im off to bed.
Navigation:
[Reply to this message]
|