时间:2021-07-01 10:21:17 帮助过:11人阅读
class WebConsole {
private static function write($data, $type = 'info') {
$method_types = array('error', 'info', 'log', 'warn');
$msg_type = '';(PS:T不错的PHP Q扣峮:304224365,验证:csl)
if(in_array($type, $method_types)) {
$msg_type = sprintf("console.%s", $type);
}else {
$msg_type = sprintf("console.%s", 'info');
}
if(is_array($data)) {
echo("");
} else {
echo("");
}
}
public static function info($data) {
self::write($data);
}
public static function error($data) {
self::write($data, 'error');
}
public static function log($data) {
self::write($data, 'log');
}
public static function warn($data) {
self::write($data, 'warn');
}
}
?>
现在,导入WebConsole类,并使用跟踪功能。
代码如下:
require_once('WebConsole.php');
$fruits = array('apple', 'mange', 'banana');
WebConsole::log($fruits);
WebConsole::info($fruits);
WebConsole::warn($fruits);
WebConsole::error($fruits);
?>
现在打开你的浏览器控制台,你会发现出现类似下面的屏幕截图: