note 54440 added to function.var-export
| From: | linus at flowingcreativity dot net | Date: | Mon, 04 Jul 2005 16:50:05 +0000 |
| Subject: | note 54440 added to function.var-export | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91433@lists.php.net to get a copy of this message | ||
<roman at DIESPAM dot feather dot org dot ru>, your function has inefficiencies and problems.
I probably speak for everyone when I ask you to test code before you add to the manual.
Since the issue of whitespace only comes up when exporting arrays, you can use the original
var_export() for all other variable types. This function does the job, and, from the outside, works
the same as var_export().
<?php
function var_export_min($var, $return = false) {
if (is_array($var)) {
$toImplode = array();
foreach ($var as $key => $value) {
$toImplode[] = var_export($key, true).'=>'.var_export_min($value, true);
}
$code = 'array('.implode(',', $toImplode).')';
if ($return) return $code;
else echo $code;
} else {
return var_export($var, $return);
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.var-export.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54440
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54440&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54440&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54440&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54440&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54440&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54440&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54440&report=yes
Search -- http://master.php.net/manage/user-notes.php