search for in the  
<unsetvar_export>
Last updated: Thu, 19 May 2005

var_dump

(PHP 3 >= 3.0.5, PHP 4, PHP 5)

var_dump -- Dumps information about a variable

Description

void var_dump ( mixed expression [, mixed expression [, ...]] )

This function displays structured information about one or more expressions that includes its type and value. Arrays and objects are explored recursively with values indented to show structure.

In PHP 5 only public, private and protected properties of objects will be returned in the output.

Tip: As with anything that outputs its result directly to the browser, you can use the output-control functions to capture the output of this function, and save it in a string (for example).

Parameters

expression

The variable you want to export.

Return Values

No value is returned.

Examples

Example 1. var_dump() example

<?php
$a
= array(1, 2, array("a", "b", "c"));
var_dump($a);
?>

The above example will output:

array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  array(3) {
    [0]=>
    string(1) "a"
    [1]=>
    string(1) "b"
    [2]=>
    string(1) "c"
  }
}
<?php

$b
= 3.1;
$c = true;
var_dump($b, $c);

?>

The above example will output:

float(3.1)
bool(true)



User Contributed Notes
var_dump
Christian Riesen
09-May-2005 05:41
There is a small quirk in it, obviously it first does the var_dump if its in the same line with other commands.

Example:
<?php
$array
= array(1,2,3);

// Does not work? Shows first the var_dump, then <pre>
echo "<pre>" . var_dump($array);

// Works perfectly as intended
echo "<pre>";
echo
var_dump($array);
?>

Also, output control is not the best way to catch the output, instead, using
$output = var_export($variable,TRUE);
fills the $output variable with just the same. See the var_export() documentation for details.
edwardzyang at thewritingpot dot com
20-Mar-2005 05:06
If you're like me and uses var_dump whenever you're debugging, you might find these two "wrapper" functions helpful.

This one automatically adds the PRE tags around the var_dump output so you get nice formatted arrays.

<?php

function var_dump_pre($mixed = null) {
  echo
'<pre>';
 
var_dump($mixed);
  echo
'</pre>';
  return
null;
}

?>

This one returns the value of var_dump instead of outputting it.

<?php

function var_dump_ret($mixed = null) {
 
ob_start();
 
var_dump($mixed);
 
$content = ob_get_contents();
 
ob_end_clean();
  return
$content;
}

?>

Fairly simple functions, but they're infinitely helpful (I use var_dump_pre() almost exclusively now).
dwatson at planandgrow dot com
09-Mar-2005 07:02
To make sure to get the nice indenting of nested arrays, you may have to put html-<pre> tags around the var_dump():

Where $a is an array--
echo "<pre>";
var_dump($a);
echo "</pre>";
anon
28-Jan-2005 09:31
var_dump(get_defined_vars());
will dump all defined variables to the browser.

<unsetvar_export>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 18:35:34 2005 EDT