首页 > 后端开发 > php教程 > [php function]arraytoString

[php function]arraytoString

WBOY
发布: 2016-06-23 14:36:28
原创
1786 人浏览过

/*  
* 这个函数用来将数组或对象重新组合成一个字符串。用在php代码中
* bug无法修补?slashes的问题
* @author bailing
*/
function  ArrayToString( $obj )
{
     // prt($obj);
     $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 ' ){
                 $t   =   stripslashes ( $objv );
                 $objv   =   str_replace ( " \t " , " \\t " , $t );
                 $objv   =   str_replace ( " \n " , " \\n "   ,   $objv );
                 $objv   =   str_replace ( " \r " , " \\r "   ,   $objv );
                 $objv   =   str_replace ( " \ "" , " \\\ ""   ,   $objv );
                 $objstring   .= " \ "" .$objv. " \ " , " ; 
            } else   if  ( $vtype == ' array ' ){
               $objstring   .= ArrayToString( $objv ) . " , " ; 
            } else   if  ( $vtype == ' object ' ){
               $objstring   .= ArrayToString( $objv ) . " , " ; 
            } else  {
                 // 值为空等其他情况
                //echo "[$vType]".$objv."=".$objkey;
               $objstring   .= " \ "" .$objv. " \ " , " ;
            }
        }
         $objstring   =   substr ( $objstring , 0 ,- 1 );
         return   $objstring . " )\n " ;
    }
}

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板