var_dump in PHP is one of the most popular server-side scripting languages for developing online applications. Its ease of use makes it simple to track problems critical to guarantee a quick code-test-learn feedback loop, no matter what you're building. 

Because var_dump in PHP was created before modern browsers, it didn't have an easy way to log errors to the browser console, even though the browser is the most common way to interact with websites and web applications. PHP is specifically designed for web application development. Also logging to the console with JavaScript is as easy as this.

In the world of development, debugging is just as vital as coding. When a developer has to verify information about a variable, for example, if a function returns an array, it's best to double-check the return type and the contents of the returned value. A developer can echo the entire contents, but var_dump in PHP has a function that also checks the datatype.

To dump information about a variable, use the var_dump in PHP. This function provides structured data about the specified variable, including its type and value. Recursively, arrays and objects are examined, with values indented to demonstrate structure. This function works well with expressions as well.

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program
Want a Top Software Development Job? Start Here!


void var_dump ($expsn)

$expsn is a single-argument function that accepts a single variable or an expression containing several space separated variables of any type.

Return Type: There is no return type for this function.

Example 1


// PHP code to illustrate the working

//  of var_dump() Function 

var_dump(var_dump(2, 2.1, TRUE, array(1, 2, 3, 4)));




Example 2


$a = array(1, 2, array("a", "b", "c"));  










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

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

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

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

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

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




Learn From The Best Mentors in the Industry!

Automation Testing Masters ProgramExplore Program
Learn From The Best Mentors in the Industry!

The Dump Helper Function

When you var_dump in PHP the information about the variable, it's a little laborious to always echo the opening pre> and ending /pre> tags.

You may make things easier by creating a function that you can reuse. For instance, consider a function to be a reusable piece of code that may be referred to by a name. It's possible for a function to have both input and output.

Many built-in PHP functions, such as var_dump in PHP, are available. You can also create your own functions with it. User-defined functions are what they're called. In the function lesson, you'll learn more about it.

The following defines a variable-accepting function called var_dump in PHP. It dumps the variable's information and wraps the output with the pre> tag.



$message = 'Dump and die example';

echo '<pre>';


echo '</pre>';


echo 'After calling the die function';



Use of var_dump() Function

  • First, use the var dump() function to dump information about the $message variable.
  • Second, invoke the die() function to quickly end the script.


Let us look at what we learned about var_dump in brief.

  • To dump information about a variable, use the var dump() function.
  • To make the output of the var_dump() method more legible, wrap it with a pre tag.
  • The die() function immediately exits the script.
  • To dump and die, use the var dump() and death() functions together.

This was all about the small and easy var_dump in PHP that will help you do multiple tasks on PHP. If you want to learn the concept to the core, then enroll in Simplilearn’s Full Stack Web Development course and advance your career. 

Our Software Development Courses Duration And Fees

Software Development Course typically range from a few weeks to several months, with fees varying based on program and institution.

Program NameDurationFees
Caltech Coding Bootcamp

Cohort Starts: 5 Aug, 2024

6 Months$ 8,000
Automation Test Engineer

Cohort Starts: 3 Jul, 2024

11 Months$ 1,499
Full Stack Developer - MERN Stack

Cohort Starts: 9 Jul, 2024

6 Months$ 1,449
Full Stack Java Developer

Cohort Starts: 16 Jul, 2024

6 Months$ 1,449