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.
 
Example 1
  1. <?php  
  2. $a = array(1, 2, array("a""b""c"));  
  3. var_dump($a);  
  4. ?>  
Example 2
  1. <?php  
  2. $a = array(1, 2, array("a""b""c"));  
  3. var_dump($a);  
  4. ?>  
  5. <?php  
  6. $var1=678;  
  7. $var2="a678";  
  8. $var3="678";  
  9. $var4="W3resource.com";  
  10. $var5=698.99;  
  11. $var6=+125689.66;  
  12. echo var_dump($var1)."<br>";  
  13. echo var_dump($var2)."<br>";  
  14. echo var_dump($var3)."<br>";  
  15. echo var_dump($var4)."<br>";  
  16. echo var_dump($var5)."<br>";  
  17. echo var_dump($var6)."<br>";  
  18. ?> 
 
Example 3
  1. <?php  
  2. $b = 3.1;  
  3. $c = true;  
  4. var_dump($b$c);  
  5. ?>  
var_dump() vs print_r()
 
The var_dump() function is for structure information and the print_r() function shows readable information about variables.
 
Example 1
  1. <?php  
  2. $name = array("Vinod""Sharad""Nitin""Manish");  
  3. var_dump($name);  
  4. ?>  
Example 2
  1. <?php  
  2. $name = array("Vinod""Sharad""Nitin""Manish");  
  3. print_r($name);  
  4. ?>  


Similar Articles