PHP如何打印参数变量?
1,原始类型可以直接写入输出
$myfile = fopen("logName.txt", "a+") or die("Unable to open file!");
fwrite($myfile, "subscribe into text ,".$result."\n,");
fclose($myfile);
2,对象类型数据输出,如下方式
//$arr :想要输出的变量
ob_start();
var_dump($arr);
$result = ob_get_clean();
$myfile = fopen("logName.txt", "a+") or die("Unable to open file!");
fwrite($myfile, "subscribe into text ,".$result."\n,");
fclose($myfile);
备注:函数穿插在需要打印的变量的位置,PHP执行后,在生成的对应的logName.txt查看变量打印的值
fwrite($myfile,输出的内容,可以拼接注释)
!!!文件fopen 之后,必须要fclose. 周期才能完整执行
补充:
1,echo PHP在页面中输出原始类型
例如:echo "msg";
2,var_dump PHP在页面中输出对象类型
例如:var_dump($msg);
3,print()打印普通类型的值
4,print_r($msg) 可以复杂类型数组等