How to print Console.log in PHP
What is console.log( )
MDN web docs explain
console.log() very well.
MDN WEB DOCS
If you are a Frontend Developer or who use web browser, you need to know well about this method. As a junior web dev, I also love printing with this method but sometime I meet obstacle.
Work with PHP
My company has a website that made by Wordpress. So i need to fix bug in in PHP environment the first thing i need to find is this.
“How can i debug with
For this reason, I decided to wrap up that method today.
How can i print Console.log( ) in PHP?
The principle is simple. PHP is a backend environment, it draws code into pieces.
console.log('this is a Variable:', $variable);
If we want to write console.log( ) like above then,
echo "<script>console.log('this is a Variable: " . $variable. "' );</script>";
So easy right? If it is little hard to understand than you can break down it.
echo "console.log('this is a Variable: " . $variable. "' );"
This way, you will be able to understand the principle of PHP to output pieces one by one.