Output an object in PHP
March 26, 2006 11:01 PM Subscribe
I remember there's some kind of output function in PHP that will print an object or array broken down into its parts.
This is insanely useful, yet I keep forgetting the name of the function.
This is insanely useful, yet I keep forgetting the name of the function.
Please note to achieve the formatting charmston displays, at least when printing to a browser, you should wrap the print_r() function in <pre> </pre>
Otherwise, it's less readable than you might like.
posted by disillusioned at 12:13 AM on March 27, 2006
Otherwise, it's less readable than you might like.
posted by disillusioned at 12:13 AM on March 27, 2006
or var_dump($variable1[, $variable2 ...]);
There's a distinction between this and print_r, but it's one of those things I've been content to forget, because it doesn't make much odds.
posted by NinjaPirate at 1:26 AM on March 27, 2006
There's a distinction between this and print_r, but it's one of those things I've been content to forget, because it doesn't make much odds.
posted by NinjaPirate at 1:26 AM on March 27, 2006
It's been years since I lifted a code to do this for my old site, but doesn't Explode do that? Just suggesting because I didn't see it already.
posted by Brainy at 6:24 AM on March 27, 2006
posted by Brainy at 6:24 AM on March 27, 2006
No,
posted by matthewr at 6:29 AM on March 27, 2006
explode
just takes a string and splits it into an array. It doesn't actually print anything.posted by matthewr at 6:29 AM on March 27, 2006
Obviously you need a mnemonic.
"The function's called print_r(), eh?"
posted by DrJohnEvans at 7:05 AM on March 27, 2006
"The function's called print_r(), eh?"
posted by DrJohnEvans at 7:05 AM on March 27, 2006
var_dump
prints very detailed output. It will give you the types for every variable. print_r
's output is more nicely formatted, but can be ambiguous. For example:print_r: hello => world
var_dump: hello => string(5) "world"
print_r: empty =>
var_dump: empty => null
or empty => string(0) ""
posted by Khalad at 7:16 AM on March 27, 2006
This thread is closed to new comments.
<?php
$ar = array('mefi'=>'metafilter','axmefi'=>'ask metafilter','more'=>array('metatalk','projects','wiki');
print_r($ar);
?>
will output
posted by charmston at 11:14 PM on March 26, 2006