In PHP I can say:
print_r($var);
What I can't do (at least I don't know how) is:
$var_info = print_r($var);
How can I accomplish the effect of putting the results of a print_r
inside a variable?
PHP v5.3.5
It is a built-in function in print_r in PHP that is used to print or display the contents of a variable. It essentially prints human-readable data about a variable. The value of the variable will be printed if it is a string, integer, or float.
print_r() function will return the output which it is supposed to print if this parameter is set to TRUE.
var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.
The print and echo are both language constructs to display strings. The echo has a void return type, whereas print has a return value of 1 so it can be used in expressions. The print_r is used to display human-readable information about a variable.
When the second parameter is set to TRUE, print_r() will return the information rather than print it
$var_info = print_r($var,true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With