CodeIgniter Forums

Full Version: Understanding print_r()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]tim042829[/eluser]
I've written a little debug stub in vim for PHP variables.
From the variable name, it expands to the following:
Code:
echo "<pre>foo: " . print_r($foo) . "</pre>"; ## DEBUG GLOBAL
Real world example where I am inspecting index.php
Code:
$controller = BASEPATH.'codeigniter/CodeIgniter'.EXT;
echo "<pre>controller: " . print_r($controller) . "</pre>"; ## DEBUG GLOBAL
And the output is
Quote:/home/http/php/ci/system/codeigniter/CodeIgniter.php
controller: 1
Note that controller: 1 is on a second line and tends to be a little
confusing. The output that I am really looking for would be
controller: /home/http/php/ci/system/codeigniter/CodeIgniter.php
OR considering that I will be dealing with complex data structures:
Quote:controller: 1
/home/http/php/ci/system/codeigniter/CodeIgniter.php

How can I make that happen?
thanks
tim

El Forum

[eluser]WanWizard[/eluser]
Check the PHP manual for print_r(). You'll notice that it prints (echo's) the parameter, and returns true.

El Forum

[eluser]tim042829[/eluser]
[quote author="WanWizard" date="1289530227"]Check the PHP manual for print_r(). You'll notice that it prints (echo's) the parameter, and returns true.[/quote]
Are you referring to http://www.php.net/manual - link contained in the PHP man page?
If so, I have yet to have found documentation for print_r() at that site.
(but have found all kinds of other interesting and useful functions)

If not, could you point me directly to the documentation?
That would give me some more clues as to how find my way around.
thanks
tim

El Forum

[eluser]WanWizard[/eluser]
Google "print_r". The first link returned is http://php.net/manual/en/function.print-r.php. Doesn't look to difficult.

El Forum

[eluser]tim042829[/eluser]
Never mind. I found the documentation under Function Index.
As http://www.php.net/manual/en/indexes.php => http://www.php.net/manual/en/function.print-r.php

BTW: The expansion that works a little better for readability is
Code:
echo "<hr>foo: " ; print_r($foo); ## DEBUG GLOBAL
The vim code :coolsmile: for you vim users is
Code:
function! PHPGlobalDebug()
    let wrd=expand("<cWORD>")
    let cmd = "norm! ^dwaecho \"<hr>" . wrd . ": \" ; " . "print_r($" . wrd ."); ## DEBUG GLOBAL"
     exe cmd
endfunction
and the keymapping I use is
Code:
inoremap <C-d><C-g>  <Esc>:call PHPGlobalDebug()<CR>A
(Obfuscated is a calling function with a filetype switch)
BTW: How did I get to be Grad Student? Heck, I'm still in first grade.