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.
Syntax:
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.
Examples:
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 // PHP code to illustrate the working // of var_dump() Function var_dump(var_dump(2, 2.1, TRUE, array(1, 2, 3, 4))); ?> |
Output:
int(2)
float(2.1)
bool(true)
array(4) {
[0]=> int(1)
[1]=> int(2)
[2]=> int(3)
[3]=> int(4)
}
NULL
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.
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | Ds\Set xor() Function
- PHP | pi( ) Function
- D3.js | d3.max() function
- PHP | Ds\Set add() Function
- PHP | pos() Function
- PHP | Ds\Map xor() Function
- PHP | pow( ) Function
- PHP | each() Function
- PHP | Ds\Map put() Function
- p5.js | str() function
- PHP | key() Function
- CSS | rgb() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.



