PHP var_dump() function

The var_dump() function is a built-in function of PHP that dumps the information about the variables. This information includes the data type and value of the variable. In case of string, it also includes the size of the string passed inside the function.

The array and object are explored recursively with values to show their structure.

In simple words, this function provides structured information about one or more variables.

Syntax

Note: It directly outputs the result to the browser.

Parameter

Expression (var1, var2, ...): variable or the value of the variable, which you want to dump.

Return Type

It does not return any value.

Examples

PHP var_dump(): with numeric and Boolean value

In case of numeric and boolean values, it prints only data type and value of the variable. See the example below to understand it better.

Output:

int(25)
bool(true) 

PHP var_dump(): with string

Output:

string(10) "Hello Alex"
string(21) "Welcome to w3cschoool"

Let's understand with the help of a diagram:

PHP var_dump() function

PHP var_dump(): multiple arguments

The var_dump() function allows us to pass multiple arguments of different types. It can dump two or more variables together.

Output:

int(23) string(11) "Hello world"

PHP var_dump(): with array

The var_dump() function allows arrays to be explored recursively with values to show their structure.

Output:

array(3) { [0]=> string(8) "Mercedes" [1]=> string(3) "BMW" [2]=> string(4) "Audi" }

array(4) { [0]=> int(52) [1]=> string(3) "Bye" [2]=> float(91.3) [3]=> array(3) { [0]=> string(5) "Apple" [1]=> string(10) "Blackberry" [2]=> string(7) "Android" } }

Note: The var_dump() function comes under the category of variable handling.






Contact US

Email:[email protected]

var_dump() function
10/30