What is the PHP Function Print_R?
print_r() is a built-in PHP function that prints human-readable information about a variable in your script. It displays a complete representation of arrays, objects, and their values, and helps developers inspect and understand the structure and composition of data structures in their code. Moreover, this function allows you to capture its output as a string, and it can be stored in a variable or passed to other functions for further processing.
The first parameter in this function is the variable that you want to display information about. The second parameter is the return type. If this is set to FALSE, and the input variable is a string, integer or float, print_r() will print its value as it is. If the return type is set to TRUE, and the input variable is an array or object, print_r() will show the array or object’s keys and elements in a format similar to an associative array.
Another important feature of this function is the isStore parameter. This is a boolean parameter that has a default value of FALSE. If you set it to True, the output of this function will be saved in a variable instead of being printed on screen. This can be useful if you are using this function to debug your application and don’t need it to display the output on screen.
Since its inception, this function has undergone several updates and improvements. Each new version brought more capabilities for customizing and simplifying the process of displaying complex data structures in your PHP application. For example, in PHP 7.0.0, this function introduced a depth parameter that lets developers control the level of deep nested structures that are traversed. This feature helps prevent excessive recursion or overwhelming amounts of data from being displayed.