oursolutionarchitectoursolutionarchitect

PHP - var_dump() Function


Definition and Usage

The function var_dump() displays structured information (type and value) about one or more expressions/variables.

Arrays and objects are explored recursively with values indented to show structure.

All public, private and protected properties of objects will be returned in the output.

Syntax

void var_dump ( mixed $value , mixed $values )

Parameters

Sr.No Parameter & Description
1

value

The expression to dump.

2

values

Further expressions to dump.

Return Values

This function returns no value. This function outputs results directly to the browser. The output can be captured using output-control functions and stored to a string.

Dependencies

PHP 4 and above

Example

Following example demonstrates use of var_dump() −

<?php
   $a = "Welcome TutorialsPoint!";
   var_dump($a);
   echo "<br>";
   $b = array(2,'hello',22.99, array('a','b',2));
   var_dump($b);
?>

Output

This will produce following result −

string(23) "Welcome TutorialsPoint!"
array(4) { 
   [0]=> int(2) 
   [1]=> string(5) "hello" 
   [2]=> float(22.99) 
   [3]=> array(3) { 
      [0]=> string(1) "a" 
      [1]=> string(1) "b" 
      [2]=> int(2) 
   } 
}

Example

Following example demonstrates storing the output of var_dump() to a variable, which can later be manipulated. To execute the example we have used two php functions (output-control functions) ob_start() and ob_get_clean(). ob_start() function turns output buffering on where as ob_get_clean() function gets current buffer contents and delete current output buffer.

<?php
   ob_start();
   var_dump("output var_dump data to a string");
   $out = ob_get_clean();
   echo $out;
   echo("<br>");
   echo substr($out,0,30);
?>

Output

This will produce following result −

string(32) "output var_dump data to a string"
string(32) "output var_dump da
php_variable_handling_functions.htm