PHP print_r() Function: Usage Guide
The print_r() function in PHP is used to display easily readable information about variables, often for debugging purposes. It outputs the values of variables, arrays, or objects in a readable format to the browser or command line.
Example of usage:
$array = array(1, 2, 3, 4, 5);
print_r($array);
Output result:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
The print_r() function also has an optional parameter true, which returns the result as a string instead of outputting it to the browser. For example:
$array = array(1, 2, 3, 4, 5);
$result = print_r($array, true);
echo $result;
This will return the string result of print_r(), which can be further processed or output.