PHP | var_dump() Function

Debugging is as important as coding in the field of development. There might occur a case when the developer needs to check information of a variable such as if a function returns an array it is best to check the return type and the contents of the returned value. A developer may echo all the contents but PHP itself provides a method to do the same and as well as checks the datatype.

The var_dump() function is used to dump information about a variable. This function displays structured information such as type and value of the given variable. Arrays and objects are explored recursively with values indented to show structure. This function is also effective with expressions.


void var_dump ($expsn)

Parameters: The function takes a single argument $expsn that may be one single variable or an expression containing several space separated variables of any type.

Return Type: This function has no return type.

Input :  $expsn = 2.7;   
Output : float(2.7)

Input : $expsn = array(1, 2, array(3, 4, 5));
Output : array(3) { 
            [0]=> int(1) 
            [1]=> int(2) 
            [2]=> array(3) { 
                    [0]=> int(3) 
                    [1]=> int(4) 
                    [2]=> int(5) 

Below program illustrates the working of var_dump() in PHP:





// PHP code to illustrate the working
//  of var_dump() Function 
var_dump(var_dump(2, 2.1, TRUE, array(1, 2, 3, 4)));



array(4) { 
  [0]=> int(1) 
  [1]=> int(2) 
  [2]=> int(3) 
  [3]=> int(4) 

Important points to note:

  • All properties of objects whether public, private or protected will be returned in the output unless the object implements a __debugInfo() method.
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.