console.log in php

Sometimes it is necessary to display the values stored in PHP to the console. If edits are made on a web site and displaying values through var_dump() is not an option.

You need to write a PHP function that will output to the console what is stored in the desired variable in PHP.

function console_log($data){ // function
    if(is_array($data) || is_object($data)){
		echo("<script>console.log('php_array: ".json_encode($data)."');</script>");
	} else {
		echo("<script>console.log('php_string: ".$data."');</script>");

// test call function


If you have any questions, want to get individual advice or you have an interesting offer, you can contact via the feedback form.

Or write to the email

By submitting the form, you agree to our privacy policy