function ArrayToPhp( $arrayName , $array )
{
$str = "<?php";
$str .= "\n\$".$arrayName." = ".ArrayToString($array).";";
$str .= "\n?>";
return $str;
}
function ArrayToString($obj){
if(empty($obj)) return "array()";
$objType=gettype($obj);
if ($objType=='array') {
$objstring = "array(";
foreach ($obj as $objkey=>$objv) {
$objstring .="'$objkey'=>";
$vtype =gettype($objv) ;
if ($vtype=='integer') {
$objstring .="$objv,";
}else if ($vtype=='double'){
$objstring .="$objv,";
}else if ($vtype=='string'){
$objstring .="'".$objv."',";
}else if ($vtype=='array'){
$objstring .="\n".ArrayToString($objv).",";
}else if ($vtype=='object'){
$objstring .="\n".ArrayToString($objv).",";
}
}
$objstring = substr($objstring,0,-1)."\n";
return $objstring.")\n";
}
}
{
$str = "<?php";
$str .= "\n\$".$arrayName." = ".ArrayToString($array).";";
$str .= "\n?>";
return $str;
}
function ArrayToString($obj){
if(empty($obj)) return "array()";
$objType=gettype($obj);
if ($objType=='array') {
$objstring = "array(";
foreach ($obj as $objkey=>$objv) {
$objstring .="'$objkey'=>";
$vtype =gettype($objv) ;
if ($vtype=='integer') {
$objstring .="$objv,";
}else if ($vtype=='double'){
$objstring .="$objv,";
}else if ($vtype=='string'){
$objstring .="'".$objv."',";
}else if ($vtype=='array'){
$objstring .="\n".ArrayToString($objv).",";
}else if ($vtype=='object'){
$objstring .="\n".ArrayToString($objv).",";
}
}
$objstring = substr($objstring,0,-1)."\n";
return $objstring.")\n";
}
}
修正了前一个版本对于空数组返回为空的bug