Example for printing structured array contents
- Can be very useful for debugging
- Shows visual depth levels using offset symbols - either default or custom
<?php
// Format any array - can be replaced by any kind of array
$array = array();
array_push($array, array("one"=>"This is one", "two"=>"This is two"));
array_push($array, array("a"=>"This is another value", "numbers"=>array(5,4,3,2,1,0)));
$array["somekey"] = "Some value";
echo "<B>Prints array using default offset symbol:</B><BR>";
print_array($array);
echo "<HR>";
echo "<B>Prints array using custom offset symbol:</B><BR>";
print_array($array, "\......");
echo "<HR>";
echo "<B>When given parameter is not an array:</B><BR>";
$not_array = "Some text";
print_array($not_array, "\......");
/************************************************
* Prints structured array contents
*/
function print_array($array, $offset_symbol = "|--", $offset = "")
{
if (!is_array($array))
{
echo "[$array] is not an array!<BR>";
return;
}