Tuesday, October 22, 2013

The difference between var_dump() and print_r()


var_dump()  displays structured information about the object / variable. This includes type and values. It also shows which array values and object properties are references.

print_r( ) output is nicer, more concise and easier to read, and more human-readable.

With print_r() it's possible to store the output into a variable, which var_dump can't do.

Example:

$obj = (object) array('qualitypoint', 'technologies', 'India');
 
var_dump($obj) will display below output in the screen.

object(stdClass)#1 (3) {
 [0]=> string(12) "qualitypoint"
 [1]=> string(12) "technologies"
 [2]=> string(5) "India"
}
 
And, print_r($obj) will display below output in the screen.

stdClass Object ( 
 [0] => qualitypoint
 [1] => technologies
 [2] => India
)