Now, more and more browsers have developed this tool or Javascript console. With these tools, we can easily display variables or array values in PHP code.
Now, more and more browsers have developed this tool or Javascript console. With these tools, we can easily display variables or array values in PHP code.
PHP is a server-side scripting language used to develop dynamic web applications. Compared with JAVA, the absence of a good server-side debugging tool is one of its limitations. Generally, we add echo, var_dump, and other statements in PHP code to display the values of variables and arrays in the browser for debugging.
Nowadays, more and more browsers have developed this tool or Javascript console. With these tools, we can easily display variables or array values in PHP code. Here is an example. In this example, the PHP code has four trace levels: info, warn, log, error, and developers can use the browser console to Display error variables and array values.
Copy the following code to the php file and save it as WebConsole. php.
The Code is as follows:
Class WebConsole {
Private static function write ($ data, $ type = 'info '){
$ Method_types = array ('error', 'info', 'log', 'warn ');
$ Msg_type = ''; (PS: T good php q buckle: 304224365, verification: 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 ("script $ msg_type ('". implode (', ', $ data). "'); script");
} Else {
Echo ("script $ msg_type ('". $ data. "'); script");
}
}
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 ');
}
}
?>
Now, import the WebConsole class and use the tracking function.
The Code is as follows:
Require_once ('webconsole. php ');
$ Fruits = array ('apple', 'mange', 'bana ');
WebConsole: log ($ fruits );
WebConsole: info ($ fruits );
WebConsole: warn ($ fruits );
WebConsole: error ($ fruits );
?>
Open your browser console and you will find a screen similar to the following: