CKTIS / PHP
print_r()
Display array keys, values and nested structure for inspection.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
print_r(mixed $value, bool $return = false): string|trueDisplay array keys, values and nested structure for inspection. With the second argument true the function returns its formatted text. By default it writes output and returns true. The values false and null have identical empty output.
Signature
print_r(mixed $value, bool $return = false): string|true
Example output
[true,"",""]
Examples
<?php
$text=print_r(["units"=>3],true);
echo json_encode([str_contains($text,"[units] => 3"),print_r(false,true),print_r(null,true)]);
Result
[true,"",""]