echo '<pre>' . var_export($data, true) . '</pre>';
OR
highlight_string("<?php\n\$data =\n" . var_export($data, true) . ";\n");
// Log debug data by date and time on a file.
error_log( '[' . date('Y-m-d H:i:s') . '] $debug_array: ' . print_r($debug_array, true) . PHP_EOL, 3, '/PATH_TO_LOG/debug_data.log');
In case we need to persist the logs, it is helpfull to add date to the log file name for easier management of logs.
// Log debug data by time on log files by date.
error_log( '[' . date('H:i:s') . '] $debug_array: ' . print_r($debug_array, true) . PHP_EOL, 3, '/PATH_TO_LOG/debug_data_' . date('d_m_Y') . '.log');
function debugToConsole($data) {
echo "<script>console.log(".json_encode($data).")</script>";
}