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
var_dump(mixed $value, mixed ...$values): void
Example
Let's output information about a string variable:
<?php
$res = 'Hello world';
var_dump($res);
?>
Code execution result:
string(11) "Hello world"
Example
Let's output information about an array:
<?php
$res = [1, 2, 3];
var_dump($res);
?>
Code execution result:
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
Example
Let's output information about several variables at once:
<?php
$str = 'abc';
$num = 123;
$arr = ['a', 'b'];
var_dump($str, $num, $arr);
?>
Code execution result:
string(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