PHP Function Reference

PHP var_dump() Function



The PHP var_dump() function displays structured information about one or more variables that includes its type and value. Arrays and objects are explored recursively with values indented to show structure.

All public, private and protected properties of objects will be returned in the output. Static class members will not be shown.

Syntax

var_dump(variable, variables)

Parameters

variable Required. Specify variable to dump information from.
variables Optional. Specify variable to dump information from. Multiple variables are allowed.

Return Value

No value is returned.

Example:

The example below shows the usage of var_dump() function.

<?php
$x = array(10, 20, array("a", "b"));
var_dump($x);

echo "\n";

$y = array(10=>"Red", 20=>"Green", 30=>"Blue",
           40=>array("Black", "White"));
var_dump($y);
?>

The output of the above code will be:

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

array(4) {
  [10]=>
  string(3) "Red"
  [20]=>
  string(5) "Green"
  [30]=>
  string(4) "Blue"
  [40]=>
  array(2) {
    [0]=>
    string(5) "Black"
    [1]=>
    string(5) "White"
  }
}

Example:

Consider one more example where multiple variables are passed in the var_dump() function.

<?php
$x = 1000;
$y = "Hello";
$z = array(1, 2, 3);

var_dump($x, $y, $z);
?>

The output of the above code will be:

int(1000)
string(5) "Hello"
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

❮ PHP Variable Handling Reference