note 56362 added to ref.var
| From: | jfrasca at sheerdev dot com | Date: | Wed, 31 Aug 2005 17:27:37 +0000 |
| Subject: | note 56362 added to ref.var | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94534@lists.php.net to get a copy of this message | ||
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;
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.var.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56362
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56362&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56362&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56362&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56362&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56362&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56362&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56362&report=yes
Search -- http://master.php.net/manage/user-notes.php