print_r() Versus var_dump()
Posted by Raj
Difference between print_r() and var_dump():
In this article, I will explain difference between print_r(), var_dump() and var_export().
var_dump():
The var_dump function displays structured information about variables/expressions that includes its type and value
Syntax
var_dump(variable1, variabl2, ....)
Example:
<?php
$str = array(1, 2, "a");
var_dump($str);
?>
OUTPUT:
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
string(1) "a"
}
print_r() :
displays human-readable information about a variable
Example:
<?php
$arr = array ('a' => 'blue', 'b' => 'Red', 'c' => 'Green');
print_r ($arr);
?>
Output:
Array
(
[a] => blue
[b] => Red
[c] => Green
)
In this article, I will explain difference between print_r(), var_dump() and var_export().
var_dump():
The var_dump function displays structured information about variables/expressions that includes its type and value
Syntax
var_dump(variable1, variabl2, ....)
Example:
<?php
$str = array(1, 2, "a");
var_dump($str);
?>
OUTPUT:
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
string(1) "a"
}
print_r() :
displays human-readable information about a variable
Example:
<?php
$arr = array ('a' => 'blue', 'b' => 'Red', 'c' => 'Green');
print_r ($arr);
?>
Output:
Array
(
[a] => blue
[b] => Red
[c] => Green
)
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
difference between print_r() and var_dump(),
PHP,
PHP interview questions and answers,
print_r(),
var_dump() and var_export()
.You can leave a response, or trackback from your own site.