• Tutorial List

PHP var_dump() function

Last updated Mar 24, 2020

PHP var_dump()

The PHP var_dump() function is used to display the structured information (type and value) of a variable. And you can also display multiple variables information at a time by using this var_dump() function.

<pre>
<?php
    // String
    $x = "This is a String";
    $y = 'Another String';
    var_dump($x, $y);

    echo "------------------------<br>";

    //integer
    $intValue = 458;
    var_dump($intValue);

    echo "------------------------<br>";

    //Float
    $floatValue = 10.5;
    var_dump($floatValue);

    echo "------------------------<br>";

    // Boolean
    $boolTrue = true;
    $boolFalse = false;
    var_dump($boolTrue, $boolFalse);

    echo "------------------------<br>";

    //Array
    $names = array("John","Mark"); 
    var_dump($names);

    echo "------------------------<br>";

    // Elephant Class
    class Elephant{
        public function legs(){
            return "4 Legs";
        }
    }

    // OBJECT (instance of the Elephant Class)
    $elephant = new Elephant();
    var_dump($elephant);

    echo "------------------------<br>";

    // Null
    $nothing = NULL;
    var_dump($nothing);
?>
</pre>
Browser Output
string(16) "This is a String"
string(14) "Another String"
------------------------
int(458) ------------------------
float(10.5) ------------------------
bool(true) bool(false) ------------------------
array(2) { [0]=> string(4) "John" [1]=> string(4) "Mark" } ------------------------
object(Elephant)#1 (0) { } ------------------------
NULL