Pages

Thursday, April 7, 2011

PHP - Getting details of a variable

var_dumpDumps information about a variable

This function displays structured information about one or more expressions that includes its type and value. Arrays and objects are explored recursively with values indented to show structure.
In PHP 5 all public, private and protected properties of objects will be returned in the output.


For example, here's an output of a variable

 array(3) { [0]=> object(stdClass)#17 (3) { ["id"]=> string(1) "1" ["news_date"]=> string(10) "2011-04-07" ["news"]=> string(15) "TEst nouvelle 1" } [1]=> object(stdClass)#18 (3) { ["id"]=> string(1) "2" ["news_date"]=> string(10) "2011-04-07" ["news"]=> string(16) "Test nouvelles 2" } [2]=> object(stdClass)#19 (3) { ["id"]=> string(1) "3" ["news_date"]=> string(10) "2011-04-07" ["news"]=> string(16) "Test nouvelles 3" } }

2 comments:

  1. Hi,

    You can use print_r() command.

    Example: var a = array();
    echo "<pre>".print_r($a,true)."</pre>";

    for better output.

    ReplyDelete