How to Display Information about Variables with the PHP var_dump Function

09/04/2021

Contents

In this article, you will learn how to display information about variables with the PHP var_dump function.

PHP var_dump function

The var_dump() function displays information about the variable(s).

In addition to the value, detailed information such as variable type and number of bytes is displayed.

This can also be used for arrays.

Syntax:

var_dump(var1, var2, ...);

Sample

Sample Code

<?php
  $a = 12;
  echo var_dump($a) . "<br>";

  $b = 12.3;
  echo var_dump($b) . "<br>";

  $c = "How to Display Information about Variables with the PHP var_dump Function";
  echo var_dump($c) . "<br>";

  $d = array("Apple", "Orange", "Banana");
  echo var_dump($d) . "<br>";

  $e = array(12, 12.3, "Plantpot", array("Apple", "Orange", "Banana"));
  echo var_dump($e) . "<br>";

  echo var_dump($a, $b, $d);

?>

Result

int(12)
float(12.3)
string(73) "How to Display Information about Variables with the PHP var_dump Function"
array(3) { [0]=> string(5) "Apple" [1]=> string(6) "Orange" [2]=> string(6) "Banana" }
array(4) { [0]=> int(12) [1]=> float(12.3) [2]=> string(8) "Plantpot" [3]=> array(3) { [0]=> string(5) "Apple" [1]=> string(6) "Orange" [2]=> string(6) "Banana" } }
int(12) float(12.3) array(3) { [0]=> string(5) "Apple" [1]=> string(6) "Orange" [2]=> string(6) "Banana" }