Variable Functions Variables For information on how variables behave, see the Variables entry in the Language Reference section of the manual. doubleval Alias of floatval Description 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. empty Determine whether a variable is set Description booleanempty mixedvar empty 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. floatval Get float value of a variable Description floatfloatval mixedvar 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. gettype Get the type of a variable Description stringgettype mixedvar 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 Description arrayget_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 Description stringget_resource_type resourcehandle 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_variables Import GET/POST/Cookie variables into the global scope Description boolimport_request_variables stringtypes stringprefix 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. intval Get integer value of a variable Description intintval mixedvar intbase 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_array Finds whether a variable is an array Description boolis_array mixedvar 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 Description boolis_bool mixedvar 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_double Alias of is_float Description This function is an alias of is_float. is_float Finds whether a variable is a float Description boolis_float mixedvar 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_int Find whether a variable is an integer Description boolis_int mixedvar 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_integer Alias of is_int Description This function is an alias of is_int. is_long Alias of is_int Description This function is an alias of is_int. is_null Finds whether a variable is &null; Description boolis_null mixedvar 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_real is_numeric Finds whether a variable is a number or a numeric string Description boolis_numeric mixedvar 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_object Finds whether a variable is an object Description boolis_object mixedvar 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_real Alias of is_float Description This function is an alias of is_float. is_resource Finds whether a variable is a resource Description boolis_resource mixedvar is_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 Description boolis_scalar mixedvar is_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_string Finds whether a variable is a string Description boolis_string mixedvar 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. isset Determine whether a variable is set Description booleanisset mixedvar mixedvar ... 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 Description voidprint_r mixedexpression print_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 Description stringserialize mixedvalue serialize 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. <function>serialize</function> example See Also: unserialize. settype Set the type of a variable Description boolsettype mixedvar stringtype 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;. <function>settype</function> example See also gettype, type-casting and type-juggling. strval Get string value of a variable Description stringstrval mixedvar 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 Description mixedunserialize stringstr unserialize 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. <function>unserialize</function> example See Also: serialize. unset Unset a given variable Description voidunset mixedvar mixedvar ... 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. <function>unset</function> 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_dump Dumps information about a variable Description voidvar_dump mixedexpression mixedexpression ... 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_export Outputs or returns a string representation of a variable Description mixedvar_export mixedexpression boolreturn 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 Description boolis_callable mixedvar boolsyntax_only stringcallable_name &warn.undocumented.func;