[PHP]使用日志进行调试

两种方法:

1.利用自定义函数:

//写日志,打印字符串
function writelog($str){
$open=fopen("log.txt","a+");
fwrite($open,$str);
fclose($open);
}

//打印数组

function writelog($array){

$open = fopen('log.txt', 'a+b');
fwrite($open, print_r($array, true));
fclose($open);

}

2.利用file_put_contents函数语句:

语法:file_put_contents(file,data,mode,context)

例如:

//打印字符串

  1. file_put_contents('log.txt',$operateID,FILE_APPEND);
  2. file_put_contents('log.txt',"HELLO",FILE_APPEND);

//打印数组

file_put_contents('log.txt',var_export($array,ture),FILE_APPEND);

原文地址:https://www.cnblogs.com/liangxuehui/p/4606838.html