What is the var_dump() function in PHP?

In PHP, the var_dump() function is one function that displays information about a variable or arrays. The information displayed includes the type of the variable and its value.

In the case of arrays, each element’s type and value is displayed, and in the case of arrays with arrays, the arrays are recursively explored to provide their details.

Syntax

void var_dump($value_1, ...$value_n);

Parameters

  • $value: The variable whose information is to be dumped.

Multiple $value parameters can also be passed.

Return value

The return type is void. This means no value is returned.

Code

<?php
// an array
$a = array(1, 2, array("first", "second", "third"));
// string
$b = "I am a string value";
//integer
$c = 58;
var_dump($a,$b,$c);
?>

Explanation

  • For the first example, the data type and value are displayed at each index of the array, including the nested array.
  • In the second example, the data type string is displayed along with the length of the string and the string value itself.
  • In the last example, the value 58 and its int type are shown.

Free Resources