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:
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:
To all the variables in the SERVER global variable:
To check what’s stored in the session: