Home PHP How to Use var_dump Function in PHP

How to Use var_dump Function in PHP


Debugging is very important as coding in the development field. There might occur a case when the developer needs to check info 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. It is possible to use var_dump function in PHP to debug your codes and return statements easily.

A developer may echo all contents but PHP itself provides a method to do the same and as well as checks the datatype.

Using var_dump Function in PHP

The var_dump() function is used to dump info about a variable. This function is used to catch out type and value on displays like structured information such as (type and value) of the given variable.

Arrays and objects are delved into recursively with values intended to show structure. This function is also constructive with the declaration.

Now I made an array whose variable name is fruits I gave some value in this variable.

$fruits = ["Guava", "Avacado", "Dragon Fruit"];



array(3) { [0]=> string(5) “Guava” [1]=> string(7) “Avacado” [2]=> string(12) “Dragon Fruit” }

As I have told you up. The var_dump out to know array type and values from an array. Many people don’t know about int, string float, now I will see, how to check which is int, string, float, etc.

$a = 100;

echo var_dump($a)  . "<br>";

$b = "wholeblogs.com"; . "<br>";

echo var_dump($b);

$c = 100.5; . "<br>"

echo var_dump($c);





The use of var_dump function in PHP helps you to know how many words are in my paragraph whenever I see my word then I don’t go to another website I catch my word in a variable and do echo var_dump(); this is quickly telling me 561 words in your paragraph so this is a simple way to check your word.

See the example below:

$paragraph =[" We are whole blogs for teaching and guiding people for any of the topics like Travelling, Technology, Health, Fashion, Beauty, Sports, etc to grow their knowledge about what the world had introduced and what we should learn first from wholeblogs. Whole blogs provide all blogs of technology, the latest trends of fashion, and all other topics on which peoples are interested.

Wholeblogs is a great platform for people who are passionate about new technology. Wholeblogs is also a very good platform for those peoples who are very curious to learn new things."];

echo var_dump($paragraph);

Var_dump function in php
Var_dump function in PHP

More about var_dump by php.net


Please enter your comment!
Please enter your name here