程序员之怒 2020-02-24
function dd_array2str($array,$lv=1){ if(is_array($array)){ $str = ‘[‘."\n"; foreach($array AS $key=>$value) { $str .= str_repeat(‘ ‘,$lv).‘\‘‘.$key.‘\‘=>‘.dd_array2str($value,$lv+1).‘,‘."\n"; } $str = substr($str,0,strlen($str)-2); $str .= "\n".str_repeat(‘ ‘,$lv-1).‘]‘; if($lv == 1) $str .= ‘;‘; return $str; }else{ $array = addslashes($array); return ‘\‘‘.$array.‘\‘‘; } }
已经做了单引号的转义
支持多维数组