New to PHP and need some help with errors?

Wondering what’s going on with your variables?

Not seeing what you are expecting?

If you are a newbie learning PHP, one of the most useful functions to know is var_dump().

It dumps the contents of a variable, so you can see it in your web browser, it’s simple to use for example:

var_dump($my_variable);

Then you can see what $my_variable contains. The data type and in the case of an array or an object. The structure will then be visible.
You will then know how to access the fields within the array / object.

Although I’m far from a newbie, var_dump() is an ever useful function. Use it to determine the value of variables and debugging your code.

var_dump() is your friend in many scenarios, remember it and use it while developing.

Example usage, if you want to see all the variables in a GET or POST request:

var_dump($_POST);
var_dump($_GET);

To all the variables in the SERVER global variable:

var_dump($_SERVER);

To check what’s stored in the session:

var_dump($_SESSION);

Leave a Reply