Entry
Please explain the functions print_r and var_dump.
Apr 9th, 2001 12:39
Philip Olson, Ben Udall,
Descriptions (from manual) :
---------------------------------
print_r -- Prints human-readable information about a variable
(PHP 4)
var_dump -- Dumps information about a variable
(PHP 3 >= 3.0.5, PHP 4)
An example :
---------------------------------
<pre>
<?php
$example = array ('str' => 'is good',
'letters' => array ('a','b','c'),
'integer' => 31,
'float/double' => 35.3787,
24 => 'hello');
echo 'print_r :'. "\n\n";
print_r ($example);
echo 'var_dump :'. "\n\n";
var_dump ($example);
?>
</pre>
Output (layout altered) :
---------------------------------
print_r :
Array
(
[str] => is good
[letters] => Array
(
[0] => a
[1] => b
[2] => c
)
[integer] => 31
[float/double] => 35.3787
[24] => hello
)
var_dump :
array(4)
{
["str"] => string(7) "is good"
["letters"] => array(3)
{
[0] => string(1) "a"
[1] => string(1) "b"
[2] => string(1) "c"
}
["integer"] => int(31)
["float/double"] => float(35.3787)
[24] => string(5) "hello"
}
Manual Entries :
---------------------------------
http://www.php.net/manual/en/function.print-r.php
http://www.php.net/manual/en/function.var-dump.php
Initially posted on php-general :
---------------------------------
http://marc.theaimsgroup.com/?l=php-general&m=98684689426976&w=2