This chapter is about php print_r var_dump functions. These functions will generate output somewhat same but having few differences.
Let’s see in details about PHP print_r var_dump functions:
bool print_r(mixed val):
print_r is used to print values in the human-readable form. The value can be a string, integer, double, array or object. If we use print_r to print array then this function will output array values in key=>value pair. Same will happen to the object.
Example:
1. print_r(“Welcome to codingkala.com.”);
Output: Welcome to codingkala.com.
2. $arr = array(’emp1′,’emp2′,’emp3′);
print_r($arr);
Output:
Array{
[0] => emp1,
[1] => emp2,
[2] => emp3
}
print_r returns boolean value as true or false.
var_dump(mixed val):
This function performs dame like print_r but it also includes variable’s type and value.
Example:
$arr = array(’emp1′,’emp2′,’emp3′);
var_dump($arr);
Output:
array (size=3) 0 => string 'emp1' (length=4) 1 => string 'emp2' (length=4) 2 => string 'emp3' (length=4)
Important points of var_dump:
- var_dump gives total size or total length of the array.
- var_dump fives datatype of the array element.
- var_dump gives a total count of characters of array elements.
Hope you have got clear information about php print_r var_dump functions from this tutorial.