note 34912 deleted from function.print-r by vincent
| From: | vincent@php.net | Date: | Mon, 11 Aug 2003 19:00:29 +0000 |
| Subject: | note 34912 deleted from function.print-r by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-53895@lists.php.net to get a copy of this message | ||
Note Submitter: tomer@parity-bit.com
----
I also 'rewrote' the syntax, because I wanted to pass a large mess of multi-dimensional
arrays and things over to another page to finally save them after the editor.
function print_var($var,$prefix = '') {
if (is_array($var)) {
foreach ($var as $key => $this) {
if (is_array($this)) {
print_var($this,"$prefix" . "[$key]");
} else {
print "$prefix" . "[$key] = $this<BR>\n";
print "<INPUT TYPE=hidden NAME=\"$prefix" . "[$key]\"
VALUE=\"$this\">\n";
}
}
} else {
print "$prefix>$var<BR>";
}
}
// examples
print_var($_POST['month'],'month');
print_var($_POST['year'],'year');
print_var($_POST['data'],'data');
This will create a handy debug output which is very compact compared to print_r (example from that
follows) and also passes on everything to another script with <INPUT TYPE=hidden> tags.
month>8
year>3
data[Zgut] = ZZ
data[Stuff and things][0][Bling] = B1
data[Stuff and things][0][Zgut] = Z1
data[Stuff and things][1][Bling] = B2
data[Stuff and things][1][Zgut] = Z2
data[Stuff and things][2][Bling] = B3
data[Stuff and things][2][Zgut] = Z3
data[Stuff and things][3][Bling] = B4
data[Stuff and things][3][Zgut] = Z4
data[Bling!] = BB