|
Posted by Summercool on 10/19/07 02:58
On Oct 18, 7:45 pm, macca <ptmcna...@googlemail.com> wrote:
> >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 )
The above code doesn't seem to print anything out...
it is mainly to compare values? then what if two variables have the
same content? can it distinguish which is which?
Navigation:
[Reply to this message]
|