PHP print_r() Function

❮ PHP Variable Handling Reference

Example

Print the information about some variables in a more human-readable way:

<?php
$a = array("red", "green", "blue");
print_r($a);

echo "<br>";

$b = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
print_r($b);
?>
Try it Yourself »

Definition and Usage

The print_r() function prints the information about a variable in a more human-readable way.


Syntax

print_r(variable, return);

Parameter Values

Parameter Description
variable Required. Specifies the variable to return information about 
return Optional. When set to true, this function will return the information (not print it). Default is false

Technical Details

Return Value: If variable is integer, float, or string, the value itself will be printed. If variable is array or object, this function returns keys and elements. If the return parameter is set to TRUE, this function returns a string
Return Type: True or String
PHP Version: 4.0+

❮ PHP Variable Handling Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.