Var Dump Function in PHP

Introduction

In this article I will explain the "var_dump" variable handling function in PHP. The var_dump()  function dumps information about a variable. It displays structured data concerning one or additional expressions that feature its kind and value. Arrays and objects are explored recursively with values indented to point out structure.

Syntax

var_dump(variable);

 

Parameter  
Variable  The variable You want to dump

No value is returned.

Example1

<?php

$a = array(1, 2, array("a", "b", "c"));

var_dump($a);

?>

Output

var1.jpg

Example2

<?php

$a = array(1, 2, array("a", "b", "c"));

var_dump($a);

?>

<?php 

$var1=678; 

$var2="a678"

$var3="678"

$var4="W3resource.com"

$var5=698.99; 

$var6=+125689.66;           

echo var_dump($var1)."<br>"

echo var_dump($var2)."<br>"

echo var_dump($var3)."<br>"

echo var_dump($var4)."<br>"

echo var_dump($var5)."<br>"

echo var_dump($var6)."<br>"

?>

Output

var2.jpg

Example3

<?php

$b = 3.1;

$c = true;

var_dump($b, $c);

?>

Output

var3.jpg

var_dump() vs print_r()

The var_dump() function is for structure information and the print_r() function shows readable information about variables.

Example1

<?php 

$name = array("Vinod", "Sharad", "Nitin", "Manish");   

var_dump($name);  

?>

Output

var4.jpg

Example2

<?php 

$name = array("Vinod", "Sharad", "Nitin", "Manish");   

print_r($name);  

?>

Output

var5.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all