note 36647 deleted from function.var-export by aidan
| From: | aidan@php.net | Date: | Wed, 09 Jun 2004 10:49:09 +0000 |
| Subject: | note 36647 deleted from function.var-export by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70622@lists.php.net to get a copy of this message | ||
Note Submitter: anonymous at coward dot org
----
If you don't have PHP version 4.2 try the following. It just about suffices for my purposes. Of
course you would need to alter this for different levels of recursion.
<?
function var_export()
{
$arg = func_get_args();
$array = $arg[0];
$return = $arg[1];
$out = "array (\n";
foreach($array as $k=>$v)
{
$out .= "\t$k =>\n";
$out .= "\tarray (\n";
$array_keys = array_keys($v);
foreach($array_keys as $k2=>$v2)
{
if(isset($array[$k][$v2]))
{ $array[$k][$v2] = sprintf("'%s'",$array[$k][$v2]); }
else
{ $array[$k][$v2] = "NULL"; }
$out .= sprintf("\t\t'%s' => %s,\n",$v2,$array[$k][$v2]);
}
$out .= "\t),\n";
}
$out .= ");";
if($return == true)
{ return $out; }
else
{ echo $out; }
}
?>