var_name($pets,get_defined_vars())
It's still not clear to me: if you already know the name of the variable is $pets, why do you need to go to any hassle to find out that the name of the variable is $pets?
But I tried your code and got
Notice: Undefined offset: 3 in C:\test.php on line 5
Call Stack:
0.0012 1. {main}() C:\test.php:0
0.0016 2. dumpvars() C:\test.php:33
Warning: Invalid argument supplied for foreach() in C:\test.php on line 5
Call Stack:
0.0012 1. {main}() C:\test.php:0
0.0016 2. dumpvars() C:\test.php:33
(I'm guessing that "<=count" should be "<count") before getting some code equivalent to the output of
function dumpvars($message, $vars){
echo "/*\n$message\n*/\n";
foreach($vars as $name=>$var)
{
echo dump($name, $var);
}
}
function dump($name, $value)
{
return '$'.$name.' = '.var_export($value,true).";\n";
}
$pets = array('cow'=>'bessie','dog'=>'fido','mice' => array('mickey','minni','mighty'));
$config = 'some setting';
$header = "Here are your vars:";
dumpvars($header, array('pets'=>$pets, 'config'=>$config));
Of course neither of these handle situations where the variable is something like $foo->bar[42].