note 42423 deleted from function.var-export by tomsommer
| From: | tomsommer@php.net | Date: | Mon, 17 May 2004 06:30:50 +0000 |
| Subject: | note 42423 deleted from function.var-export by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69690@lists.php.net to get a copy of this message | ||
Note Submitter: php (at) burtsev .dot. com
----
I'm sorry the I've fixed one little mistake:
$out .= ($i + 1 == $num ? "\n" : ",\n");
} else
$out .= '&$GLOBALS' . "\n";
was changed to
} else
$out .= '&$GLOBALS' . "\n";
$out .= ($i + 1 == $num ? "\n" : ",\n");
Now it handles the $GLOBALS properly.
if (!function_exists("var_export")) {
function var_export($array, $return = false, $tabs = "")
{
if ( is_array($array) )
{
$out .= "array(\n";
$keys = array_keys($array);
$num = count($keys);
for ($i = 0; $i < $num; $i++)
{
if (is_string($keys[$i]))
$out .= $tabs . "\t" . '"' . $keys[$i] . '" => ';
else
$out .= $tabs . "\t" . $keys[$i] . ' => ';
if (!isset($array[$keys[$i]]["GLOBALS"]["GLOBALS"]["GLOBALS"]))
{
switch(gettype($array[$keys[$i]]))
{
case "array":
$out .= var_export($array[$keys[$i]], true, $tabs . "\t");
break;
case "string": case "NULL":
$out .= '"' . $array[$keys[$i]] . '"';
break;
default:
$out .= $array[$keys[$i]];
break;
}
} else
$out .= '&$GLOBALS' . "\n";
$out .= ($i + 1 == $num ? "\n" : ",\n");
}
$out .= $tabs . ')';
} else
$out = $array;
if ($return)
return $out;
echo $out;
}
}