var_dump()

Description

The var_dump() function dumps (prints) information about an expression. For scalar expressions the output includes the expression’s type and value. For compound expressions such as arrays and objects, the output includes an indented list of types and values, showing the structure of the expression.

Syntax


void var_dump( mixed $expr [, mixed $expr]... )

Parameters

$expr
The expression who’s information is to be dumped.

Return Value

void
This function has no return value.

Examples

1. Calling var_dump() for a Variety of Types

This example creates variables of types Boolean, integer, float, string, array, object, resource, and null. The var_dump() function is called on each of the variables.

<?php
$boolVal     = true;
$intVal      = 6;
$floatVal    = 3.14;
$stringVal   = "Hello";
$arrayVal    = array( 1, "two", 3.4 );
$objectVal   = new stdClass;
$resourceVal = fopen("./data.txt", "r");
$nullVal     = null;
 
var_dump( $boolVal );
var_dump( $intVal );
var_dump( $floatVal );
var_dump( $stringVal );
var_dump( $arrayVal );
var_dump( $objectVal );
var_dump( $resourceVal );
var_dump( $nullVal );
 
fclose( $resourceVal );
?>

The format of the var_dump() output for each of the types is shown below.

bool(true)
int(6)
float(3.14)
string(5) "Hello"
array(3) {
  [0]=>
  int(1)
  [1]=>
  string(3) "two"
  [2]=>
  float(3.4)
}
object(stdClass)#1 (0) {
}
resource(5) of type (stream)
NULL

2. Nested Arrays

This example shows the format of var_dump() output when passed a nested array. The $arrayVal variable is assigned a four element array, where the third element is, itself, an array.

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

The var_dump() function shows the structure of the array with indentation. Note that for each element of the array both the data type and value are shown.

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

3. Objects

See Also

References