note 73976 deleted from ref.array by levim
| From: | levim@php.net | Date: | Tue, 06 May 2014 22:08:52 +0000 |
| Subject: | note 73976 deleted from ref.array by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-199464@lists.php.net to get a copy of this message | ||
Note Submitter: info at joolee dot nl
----
A slight modification in the arraytostring function, posted below. This function lists an array the
same way you would define it in PHP.
<?PHP
function arraytostring($array, $depth = 0)
{
if($depth > 0)
$tab = implode('', array_fill(0, $depth, "\t"));
$text.="array(\n";
$count=count($array);
foreach ($array as $key=>$value)
{
$x++;
if (is_array($value))
{
if(substr($text,-1,1)==')') $text .= ',';
$text.=$tab."\t".'"'.$key.'"'." =>
".arraytostring($value, $depth+1);
continue;
}
$text.=$tab."\t"."\"$key\" => \"$value\"";
if ($count!=$x) $text.=",\n";
}
$text.="\n".$tab.")\n";
if(substr($text, -4, 4)=='),),')$text.='))';
return $text;
}
?>