PHP : Function Reference : Variable Handling Functions
No external libraries are needed to build this extension.
There is no installation needed to use these
functions; they are part of the PHP core.
The behaviour of these functions is affected by settings in php.ini .
Table 328. Variables Configuration Options
Name |
Default |
Changeable |
Changelog |
unserialize_callback_func |
NULL |
PHP_INI_ALL |
Available since PHP 4.2.0. |
For further details and definitions of the
PHP_INI_* constants, see the Appendix I, php.ini directives.
Here's a short explanation of
the configuration directives.
-
unserialize_callback_func
string
-
The unserialize() callback function will called
(with the undefined class' name as parameter), if the unserializer
finds an undefined class which should be instanciated. A warning
appears if the specified function is not defined, or if the function
doesn't include/implement the missing class. So only set this entry,
if you really want to implement such a callback-function.
See also unserialize().
This extension has no resource types defined.
This extension has no constants defined.
tapken
This function will return a nice tree-view of an array. It's like var_dump but much prettier :-)
Very useful to analyze an array while debugging.
function parray($array,$prep = '') {
/* (c) by Roland Tapken <tapken@engter.de> */
$prep = "$prep|";
while(list($key,$val) = each($array)) {
$type = gettype($val);
if(is_array($val)) {
$line = "-+ $key ($type)\n";
$line .= parray($val,"$prep ");
} else {
$line = "-> $key = \"$val\" ($type)\n";
}
$ret .= $prep.$line;
}
return $ret;
}
Example:
$array = array("test",2,array("foo" => "bar"), 4.23);
echo "<pre>";
echo parray($array);
echo "</pre>";
This will print:
|-> 0 = "test" (string)
|-> 1 = "2" (integer)
|-+ 2 (array)
| |-> foo = "bar" (string)
|-> 3 = "4.23" (double)
skelley
Sorry to say Mykolas, but your definition would not be correct.
isempty() evaluates to true for NULL, 0, "", false or 'not set' for any variable, object etc. that can be set to a value.
isset() evaluates to true if the variable, object etc. exists at all, whether it is 'empty' or not.
Example:
$foo = 0;
isset($foo); //will evaluate to true.
!empty($foo); //will evaluate to false.
unset($foo);
isset($foo); //will evaluate to false.
!empty($foo); //will evaluate to false.
jfrasca
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;
}
}
?>
|