Variable FunctionsVariables
For information on how variables behave, see
the Variables entry in
the Language Reference section of the manual.
doublevalAlias of floatvalDescription
This function is an alias of floatval.
This alias is a left-over from a function-renaming. In older versions of
PHP you'll need to use this alias of the floatval
function, because floatval wasn't yet available in
that version.
emptyDetermine whether a variable is setDescriptionbooleanemptymixedvarempty is a language construct.
This is the opposite of
(boolean) var,
except that no warning is generated when the variable is not set.
See converting
to boolean for more information.
Note that this is meaningless when used on anything which isn't a
variable; i.e. empty (addslashes ($name)) has
no meaning since it would be checking whether something which
isn't a variable is a variable with a &false; value.
See also isset and
unset.
floatvalGet float value of a variableDescriptionfloatfloatvalmixedvar
Returns the float value of var.
Var may be any scalar type. You cannot use
floatval on arrays or objects.
See also intval,
strval, settype and
Type
juggling.
gettypeGet the type of a variableDescriptionstringgettypemixedvar
Returns the type of the PHP variable
var.
Never use gettype to test for a certain type,
since the returned string may be subject to change in a future version.
In addition, it is slow too, as it involves string comparision .
Instead, use the is_* functions.
Possibles values for the returned string are:
"boolean" (since PHP 4)"integer""double" (for historical reasons "double" is
returned in case of a float, and not simply
"float")"string""array""object""resource" (since PHP 4)"NULL" (since PHP 4)"user function" (PHP 3 only, deprecated)"unknown type"
For PHP 4, you should use function_exists and
method_exists to replace the prior usage of
gettype on a function.
See also
settype,
is_array,
is_bool,
is_float,
is_integer,
is_null,
is_numeric,
is_object,
is_resource,
is_scalar, and
is_string.
get_defined_vars
Returns an array of all defined variables
Descriptionarrayget_defined_vars
This function returns an multidimensional array containing a list of
all defined variables, be them environment, server or user-defined
variables.
See also get_defined_functions and
get_defined_constants.
get_resource_type
Returns the resource type
Descriptionstringget_resource_typeresourcehandle
This function returns a string representing the type of the
resource passed to it. If the paramater is not a
valid resource, it
generates an error.
doc)."\n";
// prints: domxml document
]]>
import_request_variablesImport GET/POST/Cookie variables into the global scopeDescriptionboolimport_request_variablesstringtypesstringprefix
Imports GET/POST/Cookie variables into the global scope. It is
useful if you disabled
register_globals,
but would like to see some variables in the global scope.
Using the types parameter, you can
specify, which request variables to import. You can use
'G', 'P' and 'C' characters respectively for GET, POST and
Cookie. These characters are not case sensitive, so you
can also use any combination of 'g', 'p' and 'c'. POST
includes the uploaded file informations. Note, that the
order of the letters matters, as using "gp", the POST
variables will overwrite GET variables with the same
name. Any other other letters then GPC are discarded.
Although the prefix argument is
optional, you will get a notice level error, if you
specify no prefix, or specify an empty string as a
prefix. This is a possible security hazard. Notice
level errors are not displayed using the default
error reporting level.
See also register_globals
and track_vars.
intvalGet integer value of a variableDescriptionintintvalmixedvarintbase
Returns the integer value of var,
using the specified base for the conversion (the default is
base 10).
var may be any scalar type. You cannot use
intval on arrays or objects.
The base argument for
intval has no effect unless the
var argument is a string.
See also floatval,
strval, settype and
Type
juggling.
is_arrayFinds whether a variable is an arrayDescriptionboolis_arraymixedvar
Returns &true; if var is an array, &false;
otherwise.
See also
is_float,
is_int,
is_integer,
is_string, and
is_object.
is_bool
Finds out whether a variable is a boolean
Descriptionboolis_boolmixedvar
Returns &true; if the var parameter is
a boolean.
See also
is_array,
is_float,
is_int,
is_integer,
is_string, and
is_object.
is_doubleAlias of is_floatDescription
This function is an alias of is_float.
is_floatFinds whether a variable is a floatDescriptionboolis_floatmixedvar
Returns &true; if var is a float,
&false; otherwise.
To test if a variable is a number or a numeric string (such as form
input, which is always a string), you must use
is_numeric.
See also
is_bool,
is_int,
is_integer,
is_numeric,
is_string,
is_array, and
is_object,
is_intFind whether a variable is an integerDescriptionboolis_intmixedvar
Returns &true; if var is an integer
&false; otherwise.
To test if a variable is a number or a numeric string (such as form
input, which is always a string), you must use
is_numeric.
See also is_bool,
is_float,
is_integer,
is_numeric,
is_string,
is_array, and
is_object.
is_integerAlias of is_intDescription
This function is an alias of is_int.
is_longAlias of is_intDescription
This function is an alias of is_int.
is_null
Finds whether a variable is &null;
Descriptionboolis_nullmixedvar
Returns &true; if var is null,
&false; otherwise.
See also is_bool,
is_numeric,
is_float,
is_int,
is_string,
is_object,
is_array,
is_integer, and
is_realis_numeric
Finds whether a variable is a number or a numeric string
Descriptionboolis_numericmixedvar
Returns &true; if var is a number or a
numeric string, &false; otherwise.
See also is_bool,
is_float,
is_int,
is_string,
is_object,
is_array, and
is_integer.
is_objectFinds whether a variable is an objectDescriptionboolis_objectmixedvar
Returns &true; if var is an object,
&false; otherwise.
See also is_bool,
is_int,
is_integer,
is_float,
is_string, and
is_array.
is_realAlias of is_floatDescription
This function is an alias of is_float.
is_resource
Finds whether a variable is a resource
Descriptionboolis_resourcemixedvaris_resource returns &true; if the variable
given by the var parameter is a
resource, otherwise it returns &false;.
See the documentation on the resource-type for
more information.
is_scalar
Finds whether a variable is a scalar
Descriptionboolis_scalarmixedvaris_scalar returns &true; if the variable
given by the var parameter is a scalar,
otherwise it returns &false;.
Scalar variables are those containing an integer,
float, string or boolean.
Types array, object and resource
or not scalar.
// string(10) "hemoglobin"
// [1]=>
// string(20) "cytochrome c oxidase"
// [2]=>
// string(10) "ferredoxin"
// }
]]>
is_scalar does not consider resource
type values to be scalar as resources are abstract datatypes
which are currently based on integers. This implementation detail should
not be relied upon, as it may change.
See also is_bool,
is_numeric,
is_float,
is_int,
is_real,
is_string,
is_object,
is_array, and
is_integer.
is_stringFinds whether a variable is a stringDescriptionboolis_stringmixedvar
Returns &true; if var is a string,
&false; otherwise.
See also is_bool,
is_int,
is_integer,
is_float,
is_real,
is_object, and
is_array.
issetDetermine whether a variable is setDescriptionbooleanissetmixedvarmixedvar...isset is a language construct.
Returns &true; if var
exists; &false; otherwise.
If a variable has been unset with unset,
it will no longer be isset. isset
will return &false; if testing a variable that has been
set to &null;. Also note that a &null; byte ("\0")
is not equivalent to the PHP &null; constant.
See also empty and
unset.
print_r
Prints human-readable information about a variable
Descriptionvoidprint_rmixedexpressionprint_r displays information about a variable
in a way that's readable by humans. If given a string,
integer or float, the value itself will be
printed. If given an array,
values will be presented in a format that shows keys and
elements. Similar notation is used for objects.
Remember that print_r will move the array
pointer to the end. Use reset to bring
it back to beginning.
&tip.ob-capture;
'apple', 'b' => 'banana', 'c' => array ('x','y','z'));
print_r ($a);
?>
]]>
Which will output:
Array
(
[a] => apple
[b] => banana
[c] => Array
(
[0] => x
[1] => y
[2] => z
)
)
]]>
Prior to PHP 4.0.4, print_r will continue forever
if given an array or object that
contains a direct or indirect reference to itself. An example
is print_r($GLOBALS) because
$GLOBALS is itself a global variable that
contains a reference to itself.
See also ob_start, var_dump,
and var_export.
serialize
Generates a storable representation of a value
Descriptionstringserializemixedvalueserialize returns a string containing a
byte-stream representation of value that
can be stored anywhere.
This is useful for storing or passing PHP values around without
losing their type and structure.
To make the serialized string into a PHP value again, use
unserialize. serialize
handles all types, except the resource-type.
You can even serialize arrays that contain
references to itself. References inside the array/object you
are serializeing will also be stored.
In PHP 3, object properties will be serialized, but methods are
lost. PHP 4 removes that limitation and restores both properties
and methods. Please see the Serializing Objects
section of Classes and
Objects for more information.
serialize example
See Also: unserialize.
settypeSet the type of a variableDescriptionboolsettypemixedvarstringtype
Set the type of variable var to
type.
Possibles values of type are:
"boolean" (or, since PHP 4.2.0, "bool")
"integer" (or, since PHP 4.2.0, "int")
"float" (only possible since PHP 4.2.0, for older versions use the
deprecated variant "double")
"string"
"array"
"object"
"null" (since PHP 4.0.8)
Returns &true; if successful; otherwise returns
&false;.
settype example
See also gettype,
type-casting and
type-juggling.
strvalGet string value of a variableDescriptionstringstrvalmixedvar
Returns the string value of var.
See the documentation on string for more information
on converting to string.
var may be any scalar type. You cannot use
strval on arrays or objects.
See also floatval,
intval, settype and
Type
juggling.
unserialize
Creates a PHP value from a stored representation
Descriptionmixedunserializestringstrunserialize takes a single serialized
variable (see serialize) and converts it
back into a PHP value. The converted value is returned, and can
be an integer, float,
string, array or object.
It's possible to set a callback-function which will be called,
if an undefined class should be instanciated during unserializing.
(to prevent getting an incomplete object "__PHP_Incomplete_Class".)
Use your &php.ini;, ini_set or .htaccess-file
to define 'unserialize_callback_func'.
Everytime an undefined class should be instanciated, it'll be called.
To disable this feature just empty this setting.
unserialize_callback_func example
In PHP 3, methods are not preserved when unserializing a
serialized object. PHP 4 removes that limitation and restores
both properties and methods. Please see the Serializing Objects
section of Classes and
Objects or more information.
unserialize example
See Also: serialize.
unsetUnset a given variableDescriptionvoidunsetmixedvarmixedvar...unset is a language construct.
unset destroys the specified variables. Note
that in PHP 3, unset will always return &true;
(actually, the integer value 1). In PHP 4, however,
unset is no longer a true function: it is
now a statement. As such no value is returned, and attempting to
take the value of unset results in a parse
error.
unset example
The behavior of unset inside of a function
can vary depending on what type of variable you are attempting to
destroy.
If a globalized variable is unset inside of
a function, only the local variable is destroyed. The variable
in the calling environment will retain the same value as before
unset was called.
The above example would output:
If a variable that is PASSED BY REFERENCE is
unset inside of a function, only the local
variable is destroyed. The variable in the calling environment
will retain the same value as before unset
was called.
The above example would output:
If a static variable is unset inside of a
function, unset destroyes the variable and all
its references.
The above example would output:
If you would like to unset a global variable
inside of a function, you can use
the $GLOBALS array to do so:
See also isset and
empty.
var_dumpDumps information about a variableDescriptionvoidvar_dumpmixedexpressionmixedexpression...
This function returns structured information about one or more expressions
that includes its type and value. Arrays are explored
recursively with values indented to show structure.
&tip.ob-capture;
Compare var_dump to
print_r.
int(1)
[1]=>
int(2)
[2]=>
array(3) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
[2]=>
string(1) "c"
}
}
*/
$b = 3.1;
$c = TRUE;
var_dump($b,$c);
/* output:
float(3.1)
bool(true)
*/
?>
]]>
var_exportOutputs or returns a string representation of a variableDescriptionmixedvar_exportmixedexpressionboolreturn
This function returns structured information about the variable that is
passed to this function. It is similar to var_dump
with the exception that the returned representation is valid PHP code.
You can also return the variable representation by using &true; as
second parameter to this function.
Compare var_export to
var_dump.
1,
1 => 2,
2 =>
array (
0 => 'a',
1 => 'b',
2 => 'c',
),
)
*/
$b = 3.1;
$v = var_export($b, TRUE);
echo $v;
/* output:
3.1
*/
?>
]]>
is_callable
Find out whether the argument is a valid callable construct
Descriptionboolis_callablemixedvarboolsyntax_onlystringcallable_name
&warn.undocumented.func;