The var_dump Function

The var_dump function displays detailed information about a variable, including its type and value. Accepts one or more parameters of any type. Especially useful when debugging code to check variable contents.

Syntax

phpvar_dump(mixed $value, mixed ...$values): void

Example

Let's output information about a string variable:

php<?php
  $res = 'Hello world';
  var_dump($res);
?>

Code execution result:

phpstring(11) "Hello world"

Example

Let's output information about an array:

php<?php
  $res = [1, 2, 3];
  var_dump($res);
?>

Code execution result:

phparray(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

Example

Let's output information about several variables at once:

php<?php
  $str = 'abc';
  $num = 123;
  $arr = ['a', 'b'];
  var_dump($str, $num, $arr);
?>

Code execution result:

phpstring(3) "abc"
int(123)
array(2) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
}

See Also

  • the print_r function,
    which outputs variable information in a human-readable form
  • the error_reporting function,
    which sets the error reporting level