PHP: Print_r & var_dump

This entry is part 48 of 54 in the series PHP Tutorial

We sidetrack a bit and look at two variable handling functions.

There are  more than a thousand functions in PHP that can help us to simplify our programming tasks.

print_r: Prints human-readable information about a variable and in the example below, an array variable.

var_dump: Dumps information about a variable

<form action="multi_checkbox1.php" method="post">
    Which sports do you like?<br>
    <input type="checkbox" name="sport[]" value="tennis"/>Tennis<br>
    <input type="checkbox" name="sport[]" value="swimming"/>Swimming<br>
    <input type="checkbox" name="sport[]" value="basketball"/>Basketball<br><br>

    <input type="submit" name="submit_name" value="Click Me"/>

if (isset($_POST['sport'])) {

You can try the above code here.  The output is as below.


They are mainly used for debugging as they allow us to take a peep into the variables.

Series Navigation<< PHP: Multi-Checkbox
PHP: Drop down select list >>

Leave a comment

Leave a Reply