print_r is one of the most useful feature of PHP, print_r prints a human-readable string representation of a variable. Sometime we need to get print_r value as sting to log or to combine the messages.
You can notice that print_r function have two argument first one is for string/array to be printed and another one use for whether it will print or return as string
#To have print_r return the data as a string, include the second argument "true": $message = print_r($obj, true);
sometime you might be need to use var_export function instead of print_r
$msg = var_export($obj, true);
I use this several time while I debugging.
Happy Debugging 🙂