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.
var_dump(var1, var2, ...);
Expression (var1, var2, ...): variable or the value of the variable, which you want to dump.
It does not return any value.
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.
<?php //PHP program to demonstrate the working of var_dump function $x = 25; //dump integer variable var_dump ($x); echo "</br>"; $y = 32.5; //dump float variable var_dump ($y); echo "</br>"; $bvalue = true; //dump boolean variable var_dump ($bvalue); ?>
Output:
PHP var_dump(): with string
<?php //dump strings $msg1 = "Hello Alex"; var_dump ($msg1); echo "</br>"; $msg2 = "Welcome to rookienerd"; var_dump ($msg2); ?>
Output:
Let's understand with the help of a diagram:
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.
<?php $x = 23; $msg = "Hello world"; //dump two variables var_dump ($x, $msg); ?>
Output:
PHP var_dump(): with array
The var_dump() function allows arrays to be explored recursively with values to show their structure.
<?php $arr = array ("Mercedes", "BMW", "Audi"); var_dump ($arr); echo "</br> </br>"; $arr1 = array (52, "Bye", 91.3, array ("Apple", "Blackberry", "Android")); var_dump ($arr1); ?>
Output: