PHP print r

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : print_r() function

Description

The print_r() function is used to print human-readable information about a variable.

Version

(PHP 4 and above)

Syntax

print_r(var_name, return_output)

Parameter

Name

Description

Required /
Optional

Type

var_name

The variable being printed.

Required

String

return_output

To capture the output in a variable, the parameter should set TRUE. The default value is FALSE.

Optional

Boolean

 

Return value

If the variable is an integer or a float or a string the function returns value of the variable. If the variable is an array the function returns keys and elements, a similarly notation is used for the object. Setting TRUE to return_output parameter the function returns a string

Example -1 :

  1. $var1='abc';  

  2. $var2=123.33;  

  3. print_r($var1);  

  4. echo'
    ';  

  5. print_r($var2);  

  6. echo'
    ';  

  7. $abc = array('Subj1'=>'Physics','Subj2'=>'Chemistry','Subj3'=>'Mathematics','Class'=>array(5,6,7,8));  

  8. print_r($abc);  

  9. ?>  

Output :

abc
123.33
Array ( [Subj1] => Physics [Subj2] => Chemistry [Subj3] => Mathematics [Class] => Array ( [0] => 5 [1] => 6 [2] => 7 [3] => 8 ) )