2
I need to show the array and store it in a variable, the functions I know that do that are var_dump
and print_r
, but they do not store in string, they already dao echo
.
What function to use?
2
I need to show the array and store it in a variable, the functions I know that do that are var_dump
and print_r
, but they do not store in string, they already dao echo
.
What function to use?
5
You can use $string = var_export($array, true);
to save a string from the array
3
The correct function is the print_r()
because it accepts a second parameter to pass the output instead of doing the dump of the same:
Example:
$b = array ('m' => 'monkey', 'foo' => 'bar', 'x' => array ('x', 'y', 'z'));
$results = print_r($b, true);
Output to the variable $results
:
Array
(
[m] => monkey
[foo] => bar
[x] => Array
(
[0] => x
[1] => y
[2] => z
)
)
The variable $results
will become a string with the above content.
See example in Ideone.
Browser other questions tagged php var-dump
You are not signed in. Login or sign up in order to post.
I took your job and gave everything ok
$results = is_array($execute) ? print_r($execute, true) : $execute;

however when sending $Results by websockets it disconnects D:– Elaine
This is another completely different and unaddressed problem in your initial question. Open a question about the problem of sending the output from
print_r($arr, true)
for websockets so that we can help you.– Zuul
I decided to use json to send, more practical. Thank you!
– Elaine