Jump to content


Photo

print array?


  • Please log in to reply
3 replies to this topic

#1 theone

theone
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 05 April 2006 - 01:30 AM

Hi Guys,

I'm having problems with a script, so i want to know how to print everything that is posted from a form to a page, ie, in $_POST

Thanks in advance,
Dave
theone

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 05 April 2006 - 01:39 AM

At the start of your script, add this line:
<?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?>

I usually put in into a function and generalize it:
<?php
function debug_dump($ary, $str, $dbg=false)
{
     if ($dbg && !empty($ary)) {
        echo ' ---- ' . $str . ' ----<br>';
        echo '<pre>' . print_r($ary,true) . '</pre>';
     }
}
?>
This way you can call the funtion throughout your code and just by changing the $dbg parameter to true, you will get dumps when your script runs.

Ken

#3 theone

theone
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 05 April 2006 - 01:46 AM

Thanks for the reply.
I decided to google it and came up with the one i knew but couldnt remember
<?
var_dump($_POST);
?>

Thanks anyways
theone

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 05 April 2006 - 01:49 AM

The [a href=\"http://www.php.net/var_dump\" target=\"_blank\"]var_dump()[/a] function and the [a href=\"http://www.php.net/print_r\" target=\"_blank\"]print_r()[/a] function produce similar results. I would surround the var_dump() the the '<pre></pre>' tags also, so tht output is easier to read.

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users