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

Your name:

Reply:


Posted by Gary L. Burnore on 10/19/07 03:01

On Fri, 19 Oct 2007 02:58:27 -0000, Summercool
<Summercoolness@gmail.com> wrote:

>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...

Heh.
--
gburnore at DataBasix dot Com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
Official .sig, Accept no substitutes. | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ 0 1 7 2 3 / Ý³Þ 3 7 4 9 3 0 Û³
Black Helicopter Repair Services, Ltd.| Official Proof of Purchase
===========================================================================

[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

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