Jump to content

Archived

This topic is now archived and is closed to further replies.

drewjoh

Output object/array information to a variable?

Recommended Posts

I'm trying to get the same effect you get say you have an array, and you can output the contents to the screen in a nice formatted way.

ie: print_r($array);

gives you:
[code]array => Array
   element1 => value1
   element2 => value2
[/code]

What I need though, is to have this formatted output given to a variable... what I'm trying to do is mail the results to myself.

Doing something like mail($to, $subject, print_r($array)); doesn't work, it just gives me a number.

Any ideas? :)

Share this post


Link to post
Share on other sites
If you look at the [a href=\"http://www.php.net/print_r\" target=\"_blank\"]manual page[/a] for the print_r() function, you will see that it takes a second parameter. When that parameter, the output can be assigned to a variable.

Example:
[code]<?php
echo '<pre>' . print_r($_SERVER,true) . '</pre>';
//
//   or
//
$body = print_r($_SERVER,true);
?>[/code]

Ken

Share this post


Link to post
Share on other sites
OHHH, awesome. Thanks Ken.

I had read that but didn't comprehend what exactly the bool return meant.

Thank you, thank you :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.