note 54467 deleted from function.print-r by derick
| From: | derick@php.net | Date: | Thu, 27 Oct 2005 10:16:08 +0000 |
| Subject: | note 54467 deleted from function.print-r by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-97674@lists.php.net to get a copy of this message | ||
Note Submitter: nsetzer at allspammustdie dot physics dot umd dot edu
----
I have found the need to print out an array that can then be cut and paste into a php script to be
assigned to a variable, so I made this function to put the ' on the keys, and appropriately
handle booleans.
<?php
function print_array($thingy, $tab='')
{
switch(true)
{
case (is_array($thingy)):
print "\n" . $tab . 'Array(' . "\n";
$newtab = $tab . "\t";
$ct = 1;
foreach($thingy as $key => $value)
{
print $newtab . "'$key' => ";
print_array($value, $newtab);
if ($ct != count($thingy))
print ',' . "\n";
++$ct;
}
print "\n" . $tab . ')';
break;
case (is_numeric($thingy)):
print $thingy;
break;
case (is_bool($thingy)):
if ($thingy)
print 'TRUE';
else
print 'FALSE';
break;
default:
print "'$thingy'";
}
}
?>