A complete example of what I use ...
<pre>
<?php
//*********** Set up some sample data
$obj = new stdClass;
$obj->a=123;
$obj->pl=44;
$obj->l=array(31,32);
$options = array(
'Orchestra'=>array(1=>'Strings', 8=>'Brass', 9=>$obj, 3=>'Woodwind', 16=>'Percussion'),
2=>'Car',
4=>'Bus',
'TV'=>array(21=>'Only Fools', 215=>'Brass Eye', 23=>'Vic Bob',44=>null, 89=>false));
//*********** Define the function
function dump($data, $indent=0) {
$retval = '';
$prefix=\str_repeat(' | ', $indent);
if (\is_numeric($data)) $retval.= "Number: $data";
elseif (\is_string($data)) $retval.= "String: '$data'";
elseif (\is_null($data)) $retval.= "NULL";
elseif ($data===true) $retval.= "TRUE";
elseif ($data===false) $retval.= "FALSE";
elseif (is_array($data)) {
$retval.= "Array (".count($data).')';
$indent++;
foreach($data AS $key => $value) {
$retval.= "\n$prefix [$key] = ";
$retval.= dump($value, $indent);
}
}
elseif (is_object($data)) {
$retval.= "Object (".get_class($data).")";
$indent++;
foreach($data AS $key => $value) {
$retval.= "\n$prefix $key -> ";
$retval.= dump($value, $indent);
}
}
return $retval;
}
//*********** Dump the data
echo dump($options);
?>
</pre>
Outputs ...
Array (4)
[Orchestra] = Array (5)
| [1] = String: 'Strings'
| [8] = String: 'Brass'
| [9] = Object (stdClass)
| | a -> Number: 123
| | pl -> Number: 44
| | l -> Array (2)
| | | [0] = Number: 31
| | | [1] = Number: 32
| [3] = String: 'Woodwind'
| [16] = String: 'Percussion'
[2] = String: 'Car'
[4] = String: 'Bus'
[TV] = Array (5)
| [21] = String: 'Only Fools'
| [215] = String: 'Brass Eye'
| [23] = String: 'Vic Bob'
| [44] = NULL
| [89] = FALSE