当前位置: 代码迷 >> 综合 >> 记录数组数据到日志的两种方法
  详细解决方案

记录数组数据到日志的两种方法

热度:42   发布时间:2024-01-16 09:03:20.0

记录字符串和数组值的方法

方法1、循环方式

方法2、php函数

 

 

 

方法1、循环方式

function xdebug($str,$pre='',$fp='xx.txt'){
    if(is_array($str)){
        foreach($str as $k=>$v){
            if(is_array($v)){
                xdebug($v,"{$pre}-{$k}");
            }else{
                file_put_contents($fp,date('H:i:s')."-{$pre}-{$k}=>{$v}/n",FILE_APPEND);
            }
        }
    }else{
        file_put_contents($fp,date('H:i:s')."-{$pre}-{$str}/n",FILE_APPEND);
    }
    file_put_contents($fp,date('H:i:s')."/n/n",FILE_APPEND);
}

 

 

方法2、php函数

 

function zdebug($str,$pre='',$fp='xx.txt'){
    if(is_array($str)){
        file_put_contents($fp,date('H:i:s').' '.var_export($str,TRUE) ."/n",FILE_APPEND);
    }else{
        file_put_contents($fp,date('H:i:s')."-{$pre}-{$str}/n",FILE_APPEND);
    }
}

  相关解决方案