PHP多维数组implode


PHP implode()[别名join]
将 一维 数组元素拼接成一个字符串

多维数组这样的implode()就没办法处理
$arr=array('a','b',array('1','2'),'c'); //二维数组
$s=implode(',',$arr);
//返回a,b,Array,c

I was a little worried about the multi-dimensional array implodes listed here,
 as they are using 'for' loops, which is bad programming practice as arrays are not always nice and neat.
I hope this helps 解决方案

function multi_implode($glue, $pieces){  
    $string='';
    if(is_array($pieces)){  
        reset($pieces);  
        while(list($key,$value)=each($pieces)){  
      $string.=$glue.multi_implode($glue, $value);  
        }
    }else{
         return $pieces;  
    }
    return trim($string, $glue);  
}  
和implode()使用参数一样
multi_implode(字符, 数组)