Reply to Re: print out variable name as well as its content

Your name:

Reply:


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.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация