note 37770 deleted from function.var-export by aidan

From: Date: Fri, 11 Jun 2004 01:53:28 +0000
Subject: note 37770 deleted from function.var-export by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-70910@lists.php.net to get a copy of this message
Note Submitter: sheimer at web dot de ---- complement to script below... [quote 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. [/quote] here it works recursive on mixed vars (but not on objects). It also rejects infinite recursion with $GLOBALS. <? 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){ $out .= $tabs . "\t$k => "; if (is_array($v) && $k != "GLOBALS"){ $out .= var_export($v, true, $tabs . "\t"); }elseif ($k !== "GLOBALS"){ $out .= $v . "\n"; }else{ $out .= "GLOBALS: not allowed!\n"; } } if ($tabs != "") $out .= $tabs . ");" ."\n"; else $out .= ");"; }else{ $out = $array; } if($return == true){ return $out; }else{ echo $out; } } ?>

« previous php.notes (#70910) next »