PHP: Output Data with var_dump

This is extremely helpful when trying to figure out what is going on in your page. When troubleshooting or just trying to figure out what data is in that mysteriously finicky array, this is a charmer:

Var_Dump the contents of an Array

<?php 
     $arr = array(); //start the array empty
     $arr[] = 1; // these 3 lines are just adding data to the array
     $arr[] = 2; // adding data
     $arr[] = 3; // adding data
     echo var_dump($arr); 
?>

Will output like this:

array(3) {
     [0]=>int(1)
     [1]=>int(2)
     [2]=>int(3)
}

Enjoy with a cold drink of your choice. Array displayed.

, , , , ,

Leave a Reply

You must be logged in to post a comment.