php将数组转化为数组字符串的方法

function array2string($arr) {
    $temp=[];
    foreach ($arr as $key=>$value){
        if(is_array($value)){
            if(!empty($value)){
                $temp[] = '\''.$key.'\'=>\''.array2string($value).'\'';
            }
            else{
                $temp[]='\''.$key.'\'=>[]';
            }
        }
        else{
            $temp[]='\''.$key.'\'=>\''.$value.'\'';
        }
    }
    $temp_str = implode(',', $temp);
    $re='['.$temp_str.']';
    return $re;
}

猜你喜欢

转载自blog.csdn.net/qq659851998/article/details/80200510