Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg

PHP : Function Reference : Variable Handling Functions

Variable Handling Functions


For information on how variables behave, see the Variables entry in the Language Reference section of the manual.


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.

Runtime Configuration

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().

Resource Types

This extension has no resource types defined.

Predefined Constants

This extension has no constants defined.

Table of Contents

debug_zval_dump — Dumps a string representation of an internal zend value to output
doubleval — Alias of floatval()
empty — Determine whether a variable is empty
floatval — Get float value of a variable
get_defined_vars — Returns an array of all defined variables
get_resource_type — Returns the resource type
gettype — Get the type of a variable
import_request_variables — Import GET/POST/Cookie variables into the global scope
intval — Get the integer value of a variable
is_array — Finds whether a variable is an array
is_binary — Finds whether a variable is a native binary string
is_bool — Finds out whether a variable is a boolean
is_buffer — Finds whether a variable is a native unicode or binary string
is_callable — Verify that the contents of a variable can be called as a function
is_double — Alias of is_float()
is_float — Finds whether the type of a variable is float
is_int — Find whether the type of a variable is integer
is_integer — Alias of is_int()
is_long — Alias of is_int()
is_null — Finds whether a variable is NULL
is_numeric — Finds whether a variable is a number or a numeric string
is_object — Finds whether a variable is an object
is_real — Alias of is_float()
is_resource — Finds whether a variable is a resource
is_scalar — Finds whether a variable is a scalar
is_string — Find whether the type of a variable is string
is_unicode — Finds whether a variable is a unicode string
isset — Determine whether a variable is set
print_r — Prints human-readable information about a variable
serialize — Generates a storable representation of a value
settype — Set the type of a variable
strval — Get string value of a variable
unserialize — Creates a PHP value from a stored representation
unset — Unset a given variable
var_dump — Dumps information about a variable
var_export — Outputs or returns a parsable string representation of a variable

Code Examples / Notes » ref.var


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 <> */
$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 = "-&gt; $key = \"$val\" ($type)\n";
$ret .= $prep.$line;
return $ret;
$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)


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.
$foo = 0;
isset($foo); //will evaluate to true.
!empty($foo); //will evaluate to false.
isset($foo); //will evaluate to false.
!empty($foo); //will evaluate to false.


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;
               return ReduceVar(reset($Value));
           return NULL;

Change Language

Follow Navioo On Twitter
.NET Functions
Apache-specific Functions
Alternative PHP Cache
Advanced PHP debugger
Array Functions
Aspell functions [deprecated]
BBCode Functions
BCMath Arbitrary Precision Mathematics Functions
PHP bytecode Compiler
Bzip2 Compression Functions
Calendar Functions
CCVS API Functions [deprecated]
Class/Object Functions
Classkit Functions
ClibPDF Functions [deprecated]
COM and .Net (Windows)
Crack Functions
Character Type Functions
Cybercash Payment Functions
Credit Mutuel CyberMUT functions
Cyrus IMAP administration Functions
Date and Time Functions
DB++ Functions
Database (dbm-style) Abstraction Layer Functions
dBase Functions
DBM Functions [deprecated]
dbx Functions
Direct IO Functions
Directory Functions
DOM Functions
DOM XML Functions
enchant Functions
Error Handling and Logging Functions
Exif Functions
Expect Functions
File Alteration Monitor Functions
Forms Data Format Functions
Fileinfo Functions
filePro Functions
Filesystem Functions
Filter Functions
Firebird/InterBase Functions
Firebird/Interbase Functions (PDO_FIREBIRD)
FriBiDi Functions
FrontBase Functions
FTP Functions
Function Handling Functions
GeoIP Functions
Gettext Functions
GMP Functions
gnupg Functions
Haru PDF Functions
hash Functions
Hyperwave Functions
Hyperwave API Functions
i18n Functions
IBM Functions (PDO_IBM)
iconv Functions
ID3 Functions
IIS Administration Functions
Image Functions
Imagick Image Library
Informix Functions
Informix Functions (PDO_INFORMIX)
Ingres II Functions
IRC Gateway Functions
PHP / Java Integration
JSON Functions
LDAP Functions
libxml Functions
Lotus Notes Functions
LZF Functions
Mail Functions
Mailparse Functions
Mathematical Functions
MaxDB PHP Extension
MCAL Functions
Mcrypt Encryption Functions
MCVE (Monetra) Payment Functions
Memcache Functions
Mhash Functions
Mimetype Functions
Ming functions for Flash
Miscellaneous Functions
mnoGoSearch Functions
Microsoft SQL Server Functions
Microsoft SQL Server and Sybase Functions (PDO_DBLIB)
Mohawk Software Session Handler Functions
mSQL Functions
Multibyte String Functions
muscat Functions
MySQL Functions
MySQL Functions (PDO_MYSQL)
MySQL Improved Extension
Ncurses Terminal Screen Control Functions
Network Functions
Newt Functions
NSAPI-specific Functions
Object Aggregation/Composition Functions
Object property and method call overloading
Oracle Functions
ODBC Functions (Unified)
ODBC and DB2 Functions (PDO_ODBC)
OpenAL Audio Bindings
OpenSSL Functions
Oracle Functions [deprecated]
Oracle Functions (PDO_OCI)
Output Control Functions
Ovrimos SQL Functions
Paradox File Access
Parsekit Functions
Process Control Functions
Regular Expression Functions (Perl-Compatible)
PDF Functions
PDO Functions
Phar archive stream and classes
PHP Options&Information
POSIX Functions
Regular Expression Functions (POSIX Extended)
PostgreSQL Functions
PostgreSQL Functions (PDO_PGSQL)
Printer Functions
Program Execution Functions
PostScript document creation
Pspell Functions
qtdom Functions
Rar Functions
GNU Readline
GNU Recode Functions
RPM Header Reading Functions
runkit Functions
SAM - Simple Asynchronous Messaging
Satellite CORBA client extension [deprecated]
SCA Functions
SDO Functions
SDO XML Data Access Service Functions
SDO Relational Data Access Service Functions
SESAM Database Functions
PostgreSQL Session Save Handler
Session Handling Functions
Shared Memory Functions
SimpleXML functions
SNMP Functions
SOAP Functions
Socket Functions
Standard PHP Library (SPL) Functions
SQLite Functions
SQLite Functions (PDO_SQLITE)
Secure Shell2 Functions
Statistics Functions
Stream Functions
String Functions
Subversion Functions
Shockwave Flash Functions
Swish Functions
Sybase Functions
TCP Wrappers Functions
Tidy Functions
Tokenizer Functions
Unicode Functions
URL Functions
Variable Handling Functions
Verisign Payflow Pro Functions
vpopmail Functions
W32api Functions
WDDX Functions
win32ps Functions
win32service Functions
xattr Functions
xdiff Functions
XML Parser Functions
XML-RPC Functions
XMLReader functions
XMLWriter Functions
XSL functions
XSLT Functions
YAZ Functions
YP/NIS Functions
Zip File Functions
Zlib Compression Functions
eXTReMe Tracker