Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
communitycreator

What is the var_dump() function in PHP?

NDUKWE CHIDERA K.

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

In PHP, the var_dump() function is one function that displays information about a variable or arrays. The information displayed includes the type of the variable and its value.

In the case of arrays, each element’s type and value is displayed, and in the case of arrays with arrays, the arrays are recursively explored to provide their details.

Syntax

void var_dump($value_1, ...$value_n);

Parameters

  • $value: The variable whose information is to be dumped.

Multiple $value parameters can also be passed.

Return value

The return type is void. This means no value is returned.

Code

<?php
// an array
$a = array(1, 2, array("first", "second", "third"));
// string
$b = "I am a string value";
//integer
$c = 58;
var_dump($a,$b,$c);
?>

Explanation

  • For the first example, the data type and value are displayed at each index of the array, including the nested array.
  • In the second example, the data type string is displayed along with the length of the string and the string value itself.
  • In the last example, the value 58 and its int type are shown.

RELATED TAGS

php
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring