note 38481 deleted from function.var-export by aidan
| From: | aidan@php.net | Date: | Fri, 11 Jun 2004 01:53:16 +0000 |
| Subject: | note 38481 deleted from function.var-export by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70909@lists.php.net to get a copy of this message | ||
Note Submitter: Alonso (alonso at mk dot com dot br)
----
Here is a better version for PHP that not have support to var_export (less than 4.2.0).
It's a little modification of the function posted below, but with a good result.
Enjoy it.
- Alonso Andres
<?php
if (!function_exists("var_export")) {
function var_export() {
$arg = func_get_args();
$array = $arg[0];
$return = $arg[1];
if (isset($arg[2]))
$tabs = $arg[2];
else
$tabs = "";
if (is_array($array)) {
$out = "array (\n";
foreach($array as $k => $v) {
if (is_numeric($k)) {
$out .= $tabs . "\t$k => ";
} else {
$out .= $tabs . "\t'$k' => ";
}
if (is_array($v) && $k != "GLOBALS"){
$out .= var_export($v, true, $tabs . "\t");
} elseif ($k !== "GLOBALS") {
if (gettype($v) != "string" && !empty($v)) {
$out .= $v . ",\n";
} else {
$out .= "'$v'" . ",\n";
}
} else {
$out .= "GLOBALS: not allowed!\n";
}
}
if ($tabs != "")
$out .= $tabs . ");" . "\n";
else
$out .= ");" . "\n";
} else {
$out = $array;
}
if ($return == true) {
return $out;
} else {
echo $out;
}
}
}
?>