Tips and Tricks

Inspect PHP Variable

tips_tricks

In this tip, we will show you how to dump a variable`s content in PHP in order to debug your application.

First, you might want to create yourself a function which will show the content of any variable you pass in, in a readable format.

Second, call this function wherever you want in your code. Refresh the page in your browser, and you’re done.

function dump($var){
// format the output to be easily readable
echo "<pre>";
// use PHP builtin function to show the content of variable
var_dump($var);
echo "</pre>";
// exit, to prevent the execution of the rest of the code
die();
}