print_r()
18th January 2021
0 Comments
Programming Language
PHP [Versions: 4, 5, 7, 8]
Syntax
Typical Usage
Displays human-readable information about a variable in PHP.
Accepted Parameters
- value (mixed) (Required): The value or expression you wish to print.
- return (boolean) (Optional) (Default = false): If set to true, the expression will be returned rather than printed.
Return Value(s)
If the output is a string, integer or float, the value will be printed. If the output is an array or object, values will be presented in a format that shows keys and elements/values.Notes
When the return parameter is used, the print_r() function uses internal output buffering so it cannot be used inside an ob_start() callback function.
Examples of print_r()
Example 1
$data = array (
'item 1',
'item 2',
'item 3',
);
print_r($data);
The above will output:
Array ( [0] => item 1 [1] => item 2 [2] => item 3 )
Similar Functions in Other Languages
- Javascript: console.log()
Was This Helpful?
If this post has helped you, please let me know. Your feedback will be highly appreciated and will help me build better content.