I needed a simple function that would reduce any kind of variable to a string or number while retaining some semblance of the data that was stored in the variable. This is what I came up with:
<?
function ReduceVar ($Value) {
switch (gettype($Value)) {
case "boolean":
case "integer":
case "double":
case "string":
case "NULL":
return $Value;
case "resource":
return get_resource_type($Value);
case "object":
return ReduceVar(get_object_vars($Value));
case "array":
if (count($Value) <= 0)
return NULL;
else
return ReduceVar(reset($Value));
default:
return NULL;
}
}
?>