PHP var_dump() function

Learn what is PHP var_dump() function and what is the use of PHP var_dump() function.

PHP var_dump()

The PHP var_dump() function is used to display the structured information (type and value) of a variable. And you can also display multiple variables information at a time by using this var_dump() function.

<?php
// This is an integer
$var2 = 256;
var_dump($var2);
?>
Browser Output
int(256)

<?php
// This is a String
$var1 = "Hello World!";
var_dump($var1);
?>
Browser Output
string(12) “Hello World!”

<?php
// This is an Array
$var1 = array('Hello', 25);

echo "<pre>";
var_dump($var1);
echo "</pre>";
?>
Browser Output
array(2) {
  [0]=>
  string(5) "Hello"
  [1]=>
  int(25)
}

Displaying multiple variables information at a time

<?php
// This is an Integer
$var1 = 145;
// This is a String
$var2 = "John Doe";
// This is an Array
$var3 = array('Hello', 25);

echo "<pre>";
var_dump($var1, $var2, $var3);
echo "</pre>";
?>
Browser Output
int(145)
string(8) "John Doe"
array(2) {
  [0]=>
  string(5) "Hello"
  [1]=>
  int(25)
}

Leave a Reply

Your email address will not be published. Required fields are marked *