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);
$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.