2012-11-13 41 views

回答

28

print_r()有第二個參數,如果作爲TRUE傳遞,則返回字符串形式的輸出。

$output = print_r($data, true); 
file_put_contents('file.txt', $output); 

你甚至可以使用cosinder功能var_export,因爲它提供了有關數據類型的更好的信息。從print_r您不能分辨變量是否爲FALSE,但var_export讓我們使用精確地查看變量的數據類型。