var_dump(): Gives all information about a variable

<?php
$var=5;
echo var_dump($var); // Output int(5)
echo "<br>";
$var='5';
echo var_dump($var); // Output  string(1) "5" 
echo "<br>";
$var=5.8;
echo var_dump($var); // output float(5.8) 
echo "<br>";
$var=+5;
echo var_dump($var); // Output int(5)
echo "<br>";
$var=-5;
echo var_dump($var); // Output  int(-5) 
echo "<br>";
$var='a123';
echo var_dump($var); // output  string(4) "a123" 
echo "<br>";
$var=True;
echo var_dump($var); // output  bool(true)
?>
Output is here
int(5) 
string(1) "5" 
float(5.8) 
int(5) 
int(-5) 
string(4) "a123" 
bool(true)
By using var_dump function we can get all details about the variable used. This function returns nothing and can take more than one variable as input. Let us try some examples.
$a=5;
var_dump($a);
The above code will return like this
int(5)
Now let us try bit different by using one string variable
$a='testing';
var_dump($a);
The output is here
string(7) "testing" 
We get all information about the string variable $a in above line. The length of the string is 7 here. Now let us try by using more than one variable.
$a=5.9;
$b='testing';
var_dump($a,$b);
Output is here
float(5.9) string(7) "testing"
We can add one array variable to our input to var_dump function.
$a=5.9;
$b='testing';
$ar=array('testing',' only ', ' at ', ' plus2net');
var_dump($a,$b,$ar);
The output is here
float(5.9) string(7) "testing" array(4) 
{ [0]=> string(7) "testing" [1]=> string(6) " only " [2]=> string(4) " at " [3]=> string(9) " plus2net" }

Example: Debugging Arrays and Objects

$arr = array("name" => "John", "age" => 25);
var_dump($arr);

class Person {
    public $name;
    public function __construct($name) {
        $this->name = $name;
    }
}
$person = new Person("Alice");
var_dump($person);

Example: Preventing Sensitive Data Dumping

$password = "secret";
$userData = ["username" => "john", "password" => $password];
unset($userData['password']);  // Remove sensitive data before dumping
var_dump($userData);
Explanation:
Complex Data Debugging: Demonstrates how to use `var_dump()` to output details of arrays and objects.
Sensitive Information: Explains how to avoid exposing sensitive data while debugging.
Comparison: Discusses how `print_r()` is less detailed compared to `var_dump()` when printing complex data types.

This helps users understand how to apply `var_dump()` effectively for debugging and avoid potential security issues.
Declaring variables Getting Type of Variable isset() empty()
Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer