I am trying to use my logger to dump variables to my logfile.
I need it to write down arrays within arrays.
Could you explain please how to do this ? (I am not sure of how to pass the sub-array of the rest of the array but here’s what I came up with, which obviously is missing something)
Thanks
function logRec($param)
{
if(!isset($param))
return;
foreach($param as $key=>$value)
{
if(is_array($value))
{
echo "<b>nested array</b><br />";
logRec(next($param));
}
else
{
echo $param;
return;
}
}
}
$par = array("ABC","DEF",array("Apple","Peach","Melon",array("Cube","Sphere","Pyramid")));
logRec($par);
I would just do this:
The second parameter on
print_r()sets it to return the output, rather than sending it to the buffer as usual.If seeing it on too many lines isn’t good for your log file, the other thing you can do is
json_encode()it, but then you have to decide if having JSON-encoded data in your log is helpful. If you are going through your logs manually, it can be. But, if you have log file analysis tools, it often is a pain.