Jump to content

Output object/array information to a variable?


drewjoh

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? :)
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.