Fluffy ElePHPant

Too much ?

Take a break and rest your eyes.

 

PHP Cheatsheets

PHP Variable Testing

Important notes on the comparisons and tests:

  1. There appear to be two null values at the start of the test. The first one is actually an unset variable, i.e. no longer in existence. The second is a variable which was set to null.
  2. Tests with Ctype and strcmp-type functions use the system default C locale. Results may vary for other locales.
  3. Some tests might seem a bit ‘silly’, for instance testing with === 'null'. The reason for adding these tests can be divided into two categories:
    1. Data received from databases and $_POST/$_GET/etc variables are always received as strings (unless a potentially used database abstraction layer changes this). So sometimes testing for a string value where a non-string variable type would be more logical, can actually make sense.
    2. Some are unfortunately regularly encountered in code and added here to illustrate why not to use them.
  4. BEWARE: some variable changing functions will not return a changed value, but will return whether the changing succeeded. You will find this indicated in the function header by the use of $copy (as the test will use a copy of the variable to not influence the other tests in the same table).

Notes on some variables:

Some of the test variables used, do not print the way they are set, either because they contain invisible characters or because they result in something else, so for your convenience, these are outlined here:

How the variable is defined:
i8 $x = 0xCC00F9; // Hexadecimal integer.
i9 $x = 052; // Octal integer.
ia $x = 0b0111001; // Binary integer (PHP5.4+).
ib $x = ‏௫‏; // Tamil digit five - entered as string as PHP itself cannot deal with it as an integer.
ic $x = ⁸₈; // Unicode superscript and subscript digit 8 - entered as a string as PHP itself cannot deal with these as integers.
f5 $x = acos(8); // = NAN
f6 $x = NAN; // = Not a number.
f7 $x = log(0); // = Infinite.
f8 $x = INF; // = Infinite.
f9 $x = 1.2345E8; // Exponent notation float.
fa $x = ⅕; // Unicode character representing 1/5 - entered as string as PHP itself cannot deal with it as a float.
sk $x = "123, \"str\"\r\n";
sn $x = "\f\t\r\n";
sp $x = "\x7f\t\r\n"

Legend / How to use the tables:

  • The error level for this test sheet has been set to E_ALL & ~E_STRICT. All errors are caught and referenced (with #links) in the tables with details of the error messages (if any) below each table. Similar error messages are grouped together for your convenience.
  • Some column labels have been shortened to avoid them taking undue space. These are indicated by a . If you mouse-over the column label you will see the full variable/test information.
  • In comparison tables, the left-top table header will indicate the comparison used and link to the relevant page in the PHP Manual.
  • In test tables, the left top table header indicates the type of tests. Both this header as well as most column headers link to their respective relevant PHP Manual pages.
  • A ‡ with a number next to a column header means there is a (linked) footnote for that entry at the bottom of the page.
  • When you mouse-over the table the row and column you are at are highlighted. To help you compare specific columns/rows, you can click on any cell to mark the column and row which the cell intersects for extra highlighting. Click again to remove this sticky highlight.

Legend to the color coding

NULL: null
Boolean: true / false
Integer: 123456789 / 0
Float: 12345.6789
String: ‘A string’
Array and Object: Indicated as such. Array keys, array values and object properties will be color coded according to the coding shown here.
Resources: Resource id #12
General typing gettype() empty() is_null() isset() (bool) if( $x ) {..} General typing
General typing gettype() empty() is_null() isset() (bool) if( $x ) {..} General typing
$x = null : ( = NULL )
‘NULL’ true true false false false $x = null : ( = NULL )
$x = null : ( = NULL )
‘NULL’ true true false false false $x = null : ( = NULL )
$x = bool : ( = false )
‘boolean’ true false true false false $x = bool : ( = false )
$x = bool : 1 ( = true )
‘boolean’ false false true true true $x = bool : 1 ( = true )
$x = int : 1
‘integer’ false false true true true $x = int : 1
$x = int : 0
‘integer’ true false true false false $x = int : 0
$x = int : -1
‘integer’ false false true true true $x = int : -1
$x = int : 42
‘integer’ false false true true true $x = int : 42
†i8$x = int : 13369593
‘integer’ false false true true true †i8$x = int : 13369593
†i9$x = int : 42
‘integer’ false false true true true †i9$x = int : 42
$x = float : 1.3
‘double’ false false true true true $x = float : 1.3
$x = float : 0.005
‘double’ false false true true true $x = float : 0.005
$x = float : 0
‘double’ true false true false false $x = float : 0
$x = float : -1.3
‘double’ false false true true true $x = float : -1.3
†f5$x = float : -1.#IND
‘double’ true false true false false †f5$x = float : -1.#IND
†f6$x = float : 0
‘double’ true false true false false †f6$x = float : 0
†f7$x = float : -1.#INF
‘double’ false false true true true †f7$x = float : -1.#INF
†f9$x = float : 123450000
‘double’ false false true true true †f9$x = float : 123450000
$x = string[0] : ‘’
‘string’ true false true false false $x = string[0] : ‘’
$x = string[1] : ‘ ’
‘string’ false false true true true $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
‘string’ false false true true true $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
‘string’ false false true true true $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
‘string’ false false true true true $x = string[1] : ‘1’
$x = string[1] : ‘0’
‘string’ true false true false false $x = string[1] : ‘0’
$x = string[2] : ‘-1’
‘string’ false false true true true $x = string[2] : ‘-1’
$x = string[2] : ‘42’
‘string’ false false true true true $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
‘string’ false false true true true $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
‘string’ false false true true true $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
‘string’ false false true true true $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
‘string’ false false true true true $x = string[4] : ‘true’
$x = string[5] : ‘false’
‘string’ false false true true true $x = string[5] : ‘false’
$x = string[4] : ‘null’
‘string’ false false true true true $x = string[4] : ‘null’
$x = string[6] : ‘123str’
‘string’ false false true true true $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
‘string’ false false true true true $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
‘string’ false false true true true $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
‘string’ false false true true true $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
‘string’ false false true true true $x = string[4] : ‘0123’
$x = array()
‘array’ true false true false false $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
‘array’ false false true true true $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
‘array’ false false true true true $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
‘object’ true false true false false $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
‘object’ false false true true true $x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #14 ( = RESOURCE )
‘resource’ false false true true true $x = resource : Resource id #14 ( = RESOURCE )
  1. Notice: Undefined index: notset
is_…() gettype() is_null() is_scalar() is_bool() is_int() is_float() is_string() is_array() is_object() is_resource() is_callable() is_numeric() is_…()
is_…() gettype() is_null() is_scalar() is_bool() is_int() is_float() is_string() is_array() is_object() is_resource() is_callable() is_numeric() is_…()
$x = null : ( = NULL )
‘NULL’ true false false false false false false false false false false $x = null : ( = NULL )
$x = null : ( = NULL )
‘NULL’ true false false false false false false false false false false $x = null : ( = NULL )
$x = bool : ( = false )
‘boolean’ false true true false false false false false false false false $x = bool : ( = false )
$x = bool : 1 ( = true )
‘boolean’ false true true false false false false false false false false $x = bool : 1 ( = true )
$x = int : 1
‘integer’ false true false true false false false false false false true $x = int : 1
$x = int : 0
‘integer’ false true false true false false false false false false true $x = int : 0
$x = int : -1
‘integer’ false true false true false false false false false false true $x = int : -1
$x = int : 42
‘integer’ false true false true false false false false false false true $x = int : 42
†i8$x = int : 13369593
‘integer’ false true false true false false false false false false true †i8$x = int : 13369593
†i9$x = int : 42
‘integer’ false true false true false false false false false false true †i9$x = int : 42
$x = float : 1.3
‘double’ false true false false true false false false false false true $x = float : 1.3
$x = float : 0.005
‘double’ false true false false true false false false false false true $x = float : 0.005
$x = float : 0
‘double’ false true false false true false false false false false true $x = float : 0
$x = float : -1.3
‘double’ false true false false true false false false false false true $x = float : -1.3
†f5$x = float : -1.#IND
‘double’ false true false false true false false false false false true †f5$x = float : -1.#IND
†f6$x = float : 0
‘double’ false true false false true false false false false false true †f6$x = float : 0
†f7$x = float : -1.#INF
‘double’ false true false false true false false false false false true †f7$x = float : -1.#INF
†f9$x = float : 123450000
‘double’ false true false false true false false false false false true †f9$x = float : 123450000
$x = string[0] : ‘’
‘string’ false true false false false true false false false false false $x = string[0] : ‘’
$x = string[1] : ‘ ’
‘string’ false true false false false true false false false false false $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
‘string’ false true false false false true false false false false true $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
‘string’ false true false false false true false false false false false $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
‘string’ false true false false false true false false false false true $x = string[1] : ‘1’
$x = string[1] : ‘0’
‘string’ false true false false false true false false false false true $x = string[1] : ‘0’
$x = string[2] : ‘-1’
‘string’ false true false false false true false false false false true $x = string[2] : ‘-1’
$x = string[2] : ‘42’
‘string’ false true false false false true false false false false true $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
‘string’ false true false false false true false false false false true $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
‘string’ false true false false false true false false false false true $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
‘string’ false true false false false true false false false false true $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
‘string’ false true false false false true false false false false false $x = string[4] : ‘true’
$x = string[5] : ‘false’
‘string’ false true false false false true false false false false false $x = string[5] : ‘false’
$x = string[4] : ‘null’
‘string’ false true false false false true false false false false false $x = string[4] : ‘null’
$x = string[6] : ‘123str’
‘string’ false true false false false true false false false false false $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
‘string’ false true false false false true false false false false false $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
‘string’ false true false false false true false false false false false $x = string[10] : ‘123, "str"’
$x = string[8] : ‘is_array’
‘string’ false true false false false true false false false true false $x = string[8] : ‘is_array’
$x = string[8] : ‘0xCC00F9’
‘string’ false true false false false true false false false false true $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
‘string’ false true false false false true false false false false true $x = string[4] : ‘0123’
$x = array()
‘array’ false false false false false false true false false false false $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
‘array’ false false false false false false true false false false false $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
‘array’ false false false false false false true false false false false $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
‘object’ false false false false false false false true false false false $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
‘object’ false false false false false false false true false false false $x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #17 ( = RESOURCE )
‘resource’ false false false false false false false false true false false $x = resource : Resource id #17 ( = RESOURCE )
  1. Notice: Undefined index: notset
Null settype ( $copy, 'null' ) (unset) unset() CastToType::_null ( $x ) ‡1 isset() empty() is_null() == null === null == 'null' === 'null' Null
Null settype ( $copy, 'null' ) (unset) unset() CastToType::_null ( $x ) ‡1 isset() empty() is_null() == null === null == 'null' === 'null' Null
$x = null : ( = NULL )
null E: not available (PHP 5+) null
#2 )
null false true true true true false false $x = null : ( = NULL )
$x = null : ( = NULL )
null E: not available (PHP 5+) null
#2 )
null false true true true true false false $x = null : ( = NULL )
$x = bool : ( = false )
null E: not available (PHP 5+) null
#2 )
null true true false true false false false $x = bool : ( = false )
$x = bool : 1 ( = true )
null E: not available (PHP 5+) null
#2 )
null true false false false false true false $x = bool : 1 ( = true )
$x = int : 1
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = int : 1
$x = int : 0
null E: not available (PHP 5+) null
#2 )
null true true false true false true false $x = int : 0
$x = int : -1
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = int : -1
$x = int : 42
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = int : 42
†i8$x = int : 13369593
null E: not available (PHP 5+) null
#2 )
null true false false false false false false †i8$x = int : 13369593
†i9$x = int : 42
null E: not available (PHP 5+) null
#2 )
null true false false false false false false †i9$x = int : 42
$x = float : 1.3
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = float : 1.3
$x = float : 0.005
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = float : 0.005
$x = float : 0
null E: not available (PHP 5+) null
#2 )
null true true false true false true false $x = float : 0
$x = float : -1.3
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = float : -1.3
†f5$x = float : -1.#IND
null E: not available (PHP 5+) null
#2 )
null true true false true false true false †f5$x = float : -1.#IND
†f6$x = float : 0
null E: not available (PHP 5+) null
#2 )
null true true false true false true false †f6$x = float : 0
†f7$x = float : -1.#INF
null E: not available (PHP 5+) null
#2 )
null true false false false false false false †f7$x = float : -1.#INF
†f9$x = float : 123450000
null E: not available (PHP 5+) null
#2 )
null true false false false false false false †f9$x = float : 123450000
$x = string[0] : ‘’
null E: not available (PHP 5+) null
#2 )
null true true false true false false false $x = string[0] : ‘’
$x = string[1] : ‘ ’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[1] : ‘1’
$x = string[1] : ‘0’
null E: not available (PHP 5+) null
#2 )
null true true false false false false false $x = string[1] : ‘0’
$x = string[2] : ‘-1’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[2] : ‘-1’
$x = string[2] : ‘42’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[4] : ‘true’
$x = string[5] : ‘false’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[5] : ‘false’
$x = string[4] : ‘null’
null E: not available (PHP 5+) null
#2 )
null true false false false false true true $x = string[4] : ‘null’
$x = string[6] : ‘123str’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = string[4] : ‘0123’
$x = array()
null E: not available (PHP 5+) null
#2 )
null true true false true false false false $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
null E: not available (PHP 5+) null
#2 )
null true true false true false false false $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #20 ( = RESOURCE )
null E: not available (PHP 5+) null
#2 )
null true false false false false false false $x = resource : Resource id #20 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Notice: Undefined variable: x
‡ 1

Uses an external library

Boolean settype ( $copy, 'bool' ) (bool) filter_var (…) filter_var (…) ‡1 ‡2 CastToType::_bool ( $x, false, false ) ‡3 is_bool() == true === true == 1 == 'true' == false === false == 0 == 'false' if( $x ) {..} if( ! $x ) {..} Boolean
Boolean settype ( $copy, 'bool' ) (bool) filter_var (…) filter_var (…) ‡1 ‡2 CastToType::_bool ( $x, false, false ) ‡3 is_bool() == true === true == 1 == 'true' == false === false == 0 == 'false' if( $x ) {..} if( ! $x ) {..} Boolean
$x = null : ( = NULL )
false false E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false true false true false false true $x = null : ( = NULL )
$x = null : ( = NULL )
false false E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false true false true false false true $x = null : ( = NULL )
$x = bool : ( = false )
false false E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) false true false false false false true true true false false true $x = bool : ( = false )
$x = bool : 1 ( = true )
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) true true true true true true false false false true true false $x = bool : 1 ( = true )
$x = int : 1
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) true false true false true false false false false false true false $x = int : 1
$x = int : 0
false false E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) false false false false false true true false true true false true $x = int : 0
$x = int : -1
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = int : -1
$x = int : 42
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = int : 42
†i8$x = int : 13369593
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false †i8$x = int : 13369593
†i9$x = int : 42
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false †i9$x = int : 42
$x = float : 1.3
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = float : 1.3
$x = float : 0.005
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = float : 0.005
$x = float : 0
false false E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) false false false false false true true false true true false true $x = float : 0
$x = float : -1.3
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = float : -1.3
†f5$x = float : -1.#IND
false false E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false true true true false true true false true †f5$x = float : -1.#IND
†f6$x = float : 0
false false E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) false false false false false true true false true true false true †f6$x = float : 0
†f7$x = float : -1.#INF
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false †f7$x = float : -1.#INF
†f9$x = float : 123450000
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false †f9$x = float : 123450000
$x = string[0] : ‘’
false false E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false true false true false false true $x = string[0] : ‘’
$x = string[1] : ‘ ’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false true false true false $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) true false true false true false false false false false true false $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) true false true false true false false false false false true false $x = string[1] : ‘1’
$x = string[1] : ‘0’
false false E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) false false false false false false true false true false false true $x = string[1] : ‘0’
$x = string[2] : ‘-1’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = string[2] : ‘-1’
$x = string[2] : ‘42’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false true false true false $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) true false true false false true false false true false true false $x = string[4] : ‘true’
$x = string[5] : ‘false’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) false false true false false false false false true true true false $x = string[5] : ‘false’
$x = string[4] : ‘null’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false true false true false $x = string[4] : ‘null’
$x = string[6] : ‘123str’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false true false true false $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = string[10] : ‘123, "str"’
$x = string[2] : ‘on’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) true false true false false false false false true false true false $x = string[2] : ‘on’
$x = string[3] : ‘off’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) false false true false false false false false true false true false $x = string[3] : ‘off’
$x = string[3] : ‘yes’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) true false true false false false false false true false true false $x = string[3] : ‘yes’
$x = string[2] : ‘no’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) false false true false false false false false true false true false $x = string[2] : ‘no’
$x = string[8] : ‘0xCC00F9’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = string[4] : ‘0123’
$x = array()
false false E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false true false false false false true $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) Array: (
  [1] => null
)
false true false false false false false false false true false $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) Array: (
  [0] => b false
  [1] => b true
  [2] => null
  [3] => null
  [4] => null
  [5] => null
)
false true false false false false false false false true false $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
false false E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false true false false false false true $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #67 ( = RESOURCE )
true true E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false true false false false false false false false true false $x = resource : Resource id #67 ( = RESOURCE )
  1. Notice: Undefined index: notset
‡ 1

Please note: On some PHP versions filter_var( $x, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) where $x = false will incorrectly return null.
Also: with the same parameters filter_var() will return false instead of null for most objects.

‡ 2

The code snippet is simplified for brevity. Please refer to the source of this file on GitHub for full details on how to use filter_var_array().

‡ 3

Uses an external library

Integers settype ( $copy, 'int' ) (int) intval() $x + 0 filter_var (…) filter_var (…) ‡1 CastToType::_int ( $x, false, false ) ‡2 abs() empty() is_int() is_numeric() ctype_digit() ‡3 preg_match (`^[0-9]+$`) preg_match (`^[0-9-]+$`) preg_match (`^[\p{N}-]+$`u) Integers
Integers settype ( $copy, 'int' ) (int) intval() $x + 0 filter_var (…) filter_var (…) ‡1 CastToType::_int ( $x, false, false ) ‡2 abs() empty() is_int() is_numeric() ctype_digit() ‡3 preg_match (`^[0-9]+$`) preg_match (`^[0-9-]+$`) preg_match (`^[\p{N}-]+$`u) Integers
$x = null : ( = NULL )
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0
true false false false false false E: not available (PHP 5.1+) $x = null : ( = NULL )
$x = null : ( = NULL )
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0
true false false false false false E: not available (PHP 5.1+) $x = null : ( = NULL )
$x = bool : ( = false )
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0
true false false false false false E: not available (PHP 5.1+) $x = bool : ( = false )
$x = bool : 1 ( = true )
1 1 1 1 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 1
false false false false true true E: not available (PHP 5.1+) $x = bool : 1 ( = true )
$x = int : 1
1 1 1 1 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 1 1
false true true false true true E: not available (PHP 5.1+) $x = int : 1
$x = int : 0
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 0 0
true true true false true true E: not available (PHP 5.1+) $x = int : 0
$x = int : -1
-1 -1 -1 -1 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) -1 1
false true true false false true E: not available (PHP 5.1+) $x = int : -1
$x = int : 42
42 42 42 42 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 42 42
false true true false true true E: not available (PHP 5.1+) $x = int : 42
†i8$x = int : 13369593
13369593 13369593 13369593 13369593 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 13369593 13369593
false true true true true true E: not available (PHP 5.1+) †i8$x = int : 13369593
†i9$x = int : 42
42 42 42 42 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 42 42
false true true false true true E: not available (PHP 5.1+) †i9$x = int : 42
†ib$x = string[3] : ‘௫’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0
false false false false false false E: not available (PHP 5.1+) †ib$x = string[3] : ‘௫’
†ic$x = string[6] : ‘⁸₈’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0
false false false false false false E: not available (PHP 5.1+) †ic$x = string[6] : ‘⁸₈’
$x = float : 1.3
1 1 1 1.3 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 1.3 false false true false false false E: not available (PHP 5.1+) $x = float : 1.3
$x = float : 0.005
0 0 0 0.005 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0.005 false false true false false false E: not available (PHP 5.1+) $x = float : 0.005
$x = float : 0
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 0 0 true false true false true true E: not available (PHP 5.1+) $x = float : 0
$x = float : -1.3
-1 -1 -1 -1.3 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 1.3 false false true false false false E: not available (PHP 5.1+) $x = float : -1.3
†f5$x = float : -1.#IND
0 0 0 -1.#IND E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 1.#QNAN true false true false false false E: not available (PHP 5.1+) †f5$x = float : -1.#IND
†f6$x = float : 0
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 0 0 true false true false true true E: not available (PHP 5.1+) †f6$x = float : 0
†f7$x = float : -1.#INF
0 0 0 -1.#INF E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 1.#INF false false true false false false E: not available (PHP 5.1+) †f7$x = float : -1.#INF
†f9$x = float : 123450000
123450000 123450000 123450000 123450000 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 123450000 123450000 false false true false true true E: not available (PHP 5.1+) †f9$x = float : 123450000
$x = string[0] : ‘’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0
true false false true false false E: not available (PHP 5.1+) $x = string[0] : ‘’
$x = string[1] : ‘ ’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0
false false false false false false E: not available (PHP 5.1+) $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
1 1 1 1 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 1 1
false false true false false false E: not available (PHP 5.1+) $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
3 3 3 3 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 3 3
false false false false false false E: not available (PHP 5.1+) $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
1 1 1 1 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 1 1
false false true true true true E: not available (PHP 5.1+) $x = string[1] : ‘1’
$x = string[1] : ‘0’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 0 0
true false true true true true E: not available (PHP 5.1+) $x = string[1] : ‘0’
$x = string[2] : ‘-1’
-1 -1 -1 -1 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) -1 1
false false true false false true E: not available (PHP 5.1+) $x = string[2] : ‘-1’
$x = string[2] : ‘42’
42 42 42 42 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 42 42
false false true true true true E: not available (PHP 5.1+) $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
1 1 1 1.3 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 1.3 false false true false false false E: not available (PHP 5.1+) $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0 false false true false false false E: not available (PHP 5.1+) $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
-1 -1 -1 -1.305 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 1.305 false false true false false false E: not available (PHP 5.1+) $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0
false false false false false false E: not available (PHP 5.1+) $x = string[4] : ‘true’
$x = string[5] : ‘false’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0
false false false false false false E: not available (PHP 5.1+) $x = string[5] : ‘false’
$x = string[4] : ‘null’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0
false false false false false false E: not available (PHP 5.1+) $x = string[4] : ‘null’
$x = string[6] : ‘123str’
123 123 123 123 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 123
false false false false false false E: not available (PHP 5.1+) $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 0
false false false false false false E: not available (PHP 5.1+) $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
123 123 123 123 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 123
false false false false false false E: not available (PHP 5.1+) $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
0 0 0 13369593 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 13369593
false false true false false false E: not available (PHP 5.1+) $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
123 123 123 123 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 123 123
false false true true true true E: not available (PHP 5.1+) $x = string[4] : ‘0123’
$x = array()
0 0 0
Fatal error ( #2 )
E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null b false
true false false false Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
1 1 1
Fatal error ( #2 )
E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) Array: (
  [1] => null
)
b false
false false false false Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
1 1 1
Fatal error ( #2 )
E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) Array: (
  [0] => null
  [1] => 1
  [2] => null
  [3] => null
  [4] => null
  [5] => null
)
b false
false false false false Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
0 0 0
Fatal error ( #2 )
E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null b false
true false false false Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
1 1 1
Fatal error ( #2 )
E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null b false
false false false false Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) $x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #117 ( = RESOURCE )
117 117 117 117 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null 117
false false false false Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) $x = resource : Resource id #117 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Fatal error: Unsupported operand types
  3. Warning: preg_match() expects parameter 2 to be string, array/object/resource given
‡ 1

The code snippet is simplified for brevity. Please refer to the source of this file on GitHub for full details on how to use filter_var_array().

‡ 2

Uses an external library

‡ 3

Important: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).
In any other case, integers are interpreted as a string containing the decimal digits of the integer.

Floats settype ( $copy, 'float' ) (float) floatval() $x + 0.0 filter_var (…) filter_var (…) ‡1 CastToType::_float ( $x, false, false ) ‡2 empty() is_float() is_numeric() ctype_digit() ‡3 preg_match (`^[0-9\.]+$`) preg_match (`^[0-9\.-]+$`) preg_match (`^[\p{N}\.-]+$`u) Floats
Floats settype ( $copy, 'float' ) (float) floatval() $x + 0.0 filter_var (…) filter_var (…) ‡1 CastToType::_float ( $x, false, false ) ‡2 empty() is_float() is_numeric() ctype_digit() ‡3 preg_match (`^[0-9\.]+$`) preg_match (`^[0-9\.-]+$`) preg_match (`^[\p{N}\.-]+$`u) Floats
$x = null : ( = NULL )
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null true false false false false false E: not available (PHP 5.1+) $x = null : ( = NULL )
$x = null : ( = NULL )
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null true false false false false false E: not available (PHP 5.1+) $x = null : ( = NULL )
$x = bool : ( = false )
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null true false false false false false E: not available (PHP 5.1+) $x = bool : ( = false )
$x = bool : 1 ( = true )
1 1 1 1 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 1 false false false false true true E: not available (PHP 5.1+) $x = bool : 1 ( = true )
$x = int : 1
1 1 1 1 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 1 false false true false true true E: not available (PHP 5.1+) $x = int : 1
$x = int : 0
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 0 true false true false true true E: not available (PHP 5.1+) $x = int : 0
$x = int : -1
-1 -1 -1 -1 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) -1 false false true false false true E: not available (PHP 5.1+) $x = int : -1
$x = int : 42
42 42 42 42 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 42 false false true false true true E: not available (PHP 5.1+) $x = int : 42
†i8$x = int : 13369593
13369593 13369593 13369593 13369593 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 13369593 false false true true true true E: not available (PHP 5.1+) †i8$x = int : 13369593
†i9$x = int : 42
42 42 42 42 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 42 false false true false true true E: not available (PHP 5.1+) †i9$x = int : 42
$x = float : 1.3
1.3 1.3 1.3 1.3 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 1.3 false true true false true true E: not available (PHP 5.1+) $x = float : 1.3
$x = float : 0.005
0.005 0.005 0.005 0.005 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 0.005 false true true false true true E: not available (PHP 5.1+) $x = float : 0.005
$x = float : 0
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 0 true true true false true true E: not available (PHP 5.1+) $x = float : 0
$x = float : -1.3
-1.3 -1.3 -1.3 -1.3 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) -1.3 false true true false false true E: not available (PHP 5.1+) $x = float : -1.3
†f5$x = float : -1.#IND
-1.#IND -1.#IND -1.#IND -1.#IND E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) -1.#IND true true true false false false E: not available (PHP 5.1+) †f5$x = float : -1.#IND
†f6$x = float : 0
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 0 true true true false true true E: not available (PHP 5.1+) †f6$x = float : 0
†f7$x = float : -1.#INF
-1.#INF -1.#INF -1.#INF -1.#INF E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) -1.#INF false true true false false false E: not available (PHP 5.1+) †f7$x = float : -1.#INF
†f9$x = float : 123450000
123450000 123450000 123450000 123450000 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 123450000 false true true false true true E: not available (PHP 5.1+) †f9$x = float : 123450000
†fa$x = string[3] : ‘⅕’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false false E: not available (PHP 5.1+) †fa$x = string[3] : ‘⅕’
$x = string[0] : ‘’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null true false false true false false E: not available (PHP 5.1+) $x = string[0] : ‘’
$x = string[1] : ‘ ’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false false E: not available (PHP 5.1+) $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
1 1 1 1 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 1 false false true false false false E: not available (PHP 5.1+) $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
3 3 3 3 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 3 false false false false false false E: not available (PHP 5.1+) $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
1 1 1 1 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 1 false false true true true true E: not available (PHP 5.1+) $x = string[1] : ‘1’
$x = string[1] : ‘0’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 0 true false true true true true E: not available (PHP 5.1+) $x = string[1] : ‘0’
$x = string[2] : ‘-1’
-1 -1 -1 -1 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) -1 false false true false false true E: not available (PHP 5.1+) $x = string[2] : ‘-1’
$x = string[2] : ‘42’
42 42 42 42 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 42 false false true true true true E: not available (PHP 5.1+) $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
1.3 1.3 1.3 1.3 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 1.3 false false true false true true E: not available (PHP 5.1+) $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 0 false false true false true true E: not available (PHP 5.1+) $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
-1.305 -1.305 -1.305 -1.305 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) -1.305 false false true false false true E: not available (PHP 5.1+) $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false false E: not available (PHP 5.1+) $x = string[4] : ‘true’
$x = string[5] : ‘false’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false false E: not available (PHP 5.1+) $x = string[5] : ‘false’
$x = string[4] : ‘null’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false false E: not available (PHP 5.1+) $x = string[4] : ‘null’
$x = string[6] : ‘123str’
123 123 123 123 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false false E: not available (PHP 5.1+) $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
0 0 0 0 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false false E: not available (PHP 5.1+) $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
123 123 123 123 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false false false E: not available (PHP 5.1+) $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
0 0 0 13369593 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false true false false false E: not available (PHP 5.1+) $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
123 123 123 123 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) 123 false false true true true true E: not available (PHP 5.1+) $x = string[4] : ‘0123’
$x = array()
0 0 0
Fatal error ( #2 )
E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null true false false false Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
1 1 1
Fatal error ( #2 )
E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) Array: (
  [1] => null
)
false false false false Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
1 1 1
Fatal error ( #2 )
E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) Array: (
  [0] => null
  [1] => 1
  [2] => 1.3
  [3] => null
  [4] => null
  [5] => null
)
false false false false Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
0 0 0
Fatal error ( #2 )
E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null true false false false Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
1 1 1
Fatal error ( #2 )
E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) $x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #165 ( = RESOURCE )
165 165 165 165 E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null false false false false Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) $x = resource : Resource id #165 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Fatal error: Unsupported operand types
  3. Warning: preg_match() expects parameter 2 to be string, array/object/resource given
‡ 1

The code snippet is simplified for brevity. Please refer to the source of this file on GitHub for full details on how to use filter_var_array().

‡ 2

Uses an external library

‡ 3

Important: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).
In any other case, integers are interpreted as a string containing the decimal digits of the integer.

Numeric tests is_numeric() ctype_digit() ‡1 preg_match (`^[\p{N}-]+$`u) preg_match (`^[\p{N}\.-]+$`u) > 0 >= 0 == 0 === 0 != 0 !== 0 < 0 <= 0 is_nan() is_finite() is_infinite() floor() ceil() round() Numeric tests
Numeric tests is_numeric() ctype_digit() ‡1 preg_match (`^[\p{N}-]+$`u) preg_match (`^[\p{N}\.-]+$`u) > 0 >= 0 == 0 === 0 != 0 !== 0 < 0 <= 0 is_nan() is_finite() is_infinite() floor() ceil() round() Numeric tests
$x = null : ( = NULL )
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true false true false 0 0 0 $x = null : ( = NULL )
$x = null : ( = NULL )
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true false true false 0 0 0 $x = null : ( = NULL )
$x = bool : ( = false )
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true false true false 0 0 0 $x = bool : ( = false )
$x = bool : 1 ( = true )
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 1 1 1 $x = bool : 1 ( = true )
$x = int : 1
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 1 1 1 $x = int : 1
$x = int : 0
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true true false false false true false true false 0 0 0 $x = int : 0
$x = int : -1
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false false false false true true true true false true false -1 -1 -1 $x = int : -1
$x = int : 42
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 42 42 42 $x = int : 42
†i8$x = int : 13369593
true true E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 13369593 13369593 13369593 †i8$x = int : 13369593
†i9$x = int : 42
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 42 42 42 †i9$x = int : 42
†ib$x = string[3] : ‘௫’
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 †ib$x = string[3] : ‘௫’
†ic$x = string[6] : ‘⁸₈’
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 †ic$x = string[6] : ‘⁸₈’
$x = float : 1.3
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 1 2 1 $x = float : 1.3
$x = float : 0.005
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 0 1 0 $x = float : 0.005
$x = float : 0
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true false true false 0 0 0 $x = float : 0
$x = float : -1.3
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false false false false true true true true false true false -2 -1 -1 $x = float : -1.3
†f5$x = float : -1.#IND
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true true false false -1.#IND -1.#IND -1.#IND †f5$x = float : -1.#IND
†f6$x = float : 0
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true false true false 0 0 0 †f6$x = float : 0
†f7$x = float : -1.#INF
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false false false false true true true true false false true -1.#INF -1.#INF -1.#INF †f7$x = float : -1.#INF
†f9$x = float : 123450000
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 123450000 123450000 123450000 †f9$x = float : 123450000
†fa$x = string[3] : ‘⅕’
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 †fa$x = string[3] : ‘⅕’
$x = string[0] : ‘’
false true E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 $x = string[0] : ‘’
$x = string[1] : ‘ ’
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 1 1 1 $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false null
#2 )
null
#3 )
null
#4 )
3 3 3 $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
true true E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 1 1 1 $x = string[1] : ‘1’
$x = string[1] : ‘0’
true true E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true false true false 0 0 0 $x = string[1] : ‘0’
$x = string[2] : ‘-1’
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false false false false true true true true false true false -1 -1 -1 $x = string[2] : ‘-1’
$x = string[2] : ‘42’
true true E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 42 42 42 $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 1 2 1 $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true false true false 0 0 0 $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false false false false true true true true false true false -2 -1 -1 $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 $x = string[4] : ‘true’
$x = string[5] : ‘false’
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 $x = string[5] : ‘false’
$x = string[4] : ‘null’
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 $x = string[4] : ‘null’
$x = string[6] : ‘123str’
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false null
#2 )
null
#3 )
null
#4 )
123 123 123 $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false null
#2 )
null
#3 )
null
#4 )
123 123 123 $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
true false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 13369593 13369593 13369593 $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
true true E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false false true false 123 123 123 $x = string[4] : ‘0123’
$x = array()
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false null
#2 )
null
#3 )
null
#4 )
b false
b false
b false
$x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false null
#2 )
null
#3 )
null
#4 )
b false
b false
b false
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false null
#2 )
null
#3 )
null
#4 )
b false
b false
b false
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false null
#2 )
null
#3 )
null
#4 )
b false
b false
b false
$x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false null
#2 )
null
#3 )
null
#4 )
b false
b false
b false
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #212 ( = RESOURCE )
false false E: not available (PHP 5.1+) E: not available (PHP 5.1+) true true false false true true false false null
#2 )
null
#3 )
null
#4 )
212 212 212 $x = resource : Resource id #212 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Warning: is_nan() expects parameter 1 to be double, string/array/object/resource given
  3. Warning: is_finite() expects parameter 1 to be double, string/array/object/resource given
  4. Warning: is_infinite() expects parameter 1 to be double, string/array/object/resource given
‡ 1

Important: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).
In any other case, integers are interpreted as a string containing the decimal digits of the integer.

String casting settype ( $copy, 'string' ) ‡1 ‡2 (string) strval() $x . '' filter_var (…) filter_var (…) ‡3 CastToType::_string ( $x, false, false ) ‡4 String casting
String casting settype ( $copy, 'string' ) ‡1 ‡2 (string) strval() $x . '' filter_var (…) filter_var (…) ‡3 CastToType::_string ( $x, false, false ) ‡4 String casting
$x = null : ( = NULL )
‘’ ‘’ ‘’ ‘ ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null $x = null : ( = NULL )
$x = null : ( = NULL )
‘’ ‘’ ‘’ ‘ ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null $x = null : ( = NULL )
$x = bool : ( = false )
‘’ ‘’ ‘’ ‘ ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null $x = bool : ( = false )
$x = bool : 1 ( = true )
‘1’ ‘1’ ‘1’ ‘1 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null $x = bool : 1 ( = true )
$x = int : 1
‘1’ ‘1’ ‘1’ ‘1 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘1’ $x = int : 1
$x = int : 0
‘0’ ‘0’ ‘0’ ‘0 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘0’ $x = int : 0
$x = int : -1
‘-1’ ‘-1’ ‘-1’ ‘-1 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘-1’ $x = int : -1
$x = int : 42
‘42’ ‘42’ ‘42’ ‘42 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘42’ $x = int : 42
†i8$x = int : 13369593
‘13369593’ ‘13369593’ ‘13369593’ ‘13369593 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘13369593’ †i8$x = int : 13369593
†i9$x = int : 42
‘42’ ‘42’ ‘42’ ‘42 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘42’ †i9$x = int : 42
$x = float : 1.3
‘1.3’ ‘1.3’ ‘1.3’ ‘1.3 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘1.3’ $x = float : 1.3
$x = float : 0.005
‘0.005’ ‘0.005’ ‘0.005’ ‘0.005 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘0.005’ $x = float : 0.005
$x = float : 0
‘0’ ‘0’ ‘0’ ‘0 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘0’ $x = float : 0
$x = float : -1.3
‘-1.3’ ‘-1.3’ ‘-1.3’ ‘-1.3 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘-1.3’ $x = float : -1.3
†f5$x = float : -1.#IND
‘-1.#IND’ ‘-1.#IND’ ‘-1.#IND’ ‘-1.#IND ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘-1.#IND’ †f5$x = float : -1.#IND
†f6$x = float : 0
‘0’ ‘0’ ‘0’ ‘0 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘0’ †f6$x = float : 0
†f7$x = float : -1.#INF
‘-1.#INF’ ‘-1.#INF’ ‘-1.#INF’ ‘-1.#INF ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘-1.#INF’ †f7$x = float : -1.#INF
†f9$x = float : 123450000
‘123450000’ ‘123450000’ ‘123450000’ ‘123450000 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘123450000’ †f9$x = float : 123450000
$x = string[0] : ‘’
‘’ ‘’ ‘’ ‘ ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null $x = string[0] : ‘’
$x = string[1] : ‘ ’
‘ ’ ‘ ’ ‘ ’ ‘  ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘ ’ $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
‘ 1’ ‘ 1’ ‘ 1’ ‘ 1 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘ 1’ $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
‘ 3 ’ ‘ 3 ’ ‘ 3 ’ ‘ 3  ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘ 3 ’ $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
‘1’ ‘1’ ‘1’ ‘1 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘1’ $x = string[1] : ‘1’
$x = string[1] : ‘0’
‘0’ ‘0’ ‘0’ ‘0 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘0’ $x = string[1] : ‘0’
$x = string[2] : ‘-1’
‘-1’ ‘-1’ ‘-1’ ‘-1 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘-1’ $x = string[2] : ‘-1’
$x = string[2] : ‘42’
‘42’ ‘42’ ‘42’ ‘42 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘42’ $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
‘1.3’ ‘1.3’ ‘1.3’ ‘1.3 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘1.3’ $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
‘0.0’ ‘0.0’ ‘0.0’ ‘0.0 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘0.0’ $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
‘-1.305’ ‘-1.305’ ‘-1.305’ ‘-1.305 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘-1.305’ $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
‘true’ ‘true’ ‘true’ ‘true ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘true’ $x = string[4] : ‘true’
$x = string[5] : ‘false’
‘false’ ‘false’ ‘false’ ‘false ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘false’ $x = string[5] : ‘false’
$x = string[4] : ‘null’
‘null’ ‘null’ ‘null’ ‘null ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘null’ $x = string[4] : ‘null’
$x = string[6] : ‘123str’
‘123str’ ‘123str’ ‘123str’ ‘123str ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘123str’ $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
‘str123’ ‘str123’ ‘str123’ ‘str123 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘str123’ $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
‘123, "str"’ ‘123, "str"’ ‘123, "str"’ ‘123, "str" ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘123, "str"’ $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
‘0xCC00F9’ ‘0xCC00F9’ ‘0xCC00F9’ ‘0xCC00F9 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘0xCC00F9’ $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
‘0123’ ‘0123’ ‘0123’ ‘0123 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘0123’ $x = string[4] : ‘0123’
$x = array()
‘Array’
#2 )
‘Array’
#2 )
‘Array’
#2 )
‘Array ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
‘Array’
#2 )
‘Array’
#2 )
‘Array’
#2 )
‘Array ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) Array: (
  [1] => ‘string’
)
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
‘Array’
#2 )
‘Array’
#2 )
‘Array’
#2 )
‘Array ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) Array: (
  [0] => null
  [1] => ‘1’
  [2] => ‘1.3’
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
‘Object’
#3 )
‘Object’
#3 )
‘Object’
#3 )
‘Object ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
‘Object’
#3 )
‘Object’
#3 )
‘Object’
#3 )
‘Object ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) ‘Object’
#3 )
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #215 ( = RESOURCE )
‘Resource id #215’ ‘Resource id #215’ ‘Resource id #215’ ‘Resource id #215 ’ E: not available (PHP 5.2.0+) E: not available (PHP 5.2.0+) null $x = resource : Resource id #215 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Notice: Array to string conversion
  3. Notice: Object to string conversion
‡ 1

Depending on your error handling settings/exception catching and your PHP version, using settype( $copy, 'string' ) on an object which does not have a __toString() method will result either in the string Object or will return a (catchable) fatal error.

‡ 2

Before PHP < 5.2.0, the __toString() method was only available to echo/print statements, so casting to string would still result in Object, even when the object contained a __toString() method.

‡ 3

The code snippet is simplified for brevity. Please refer to the source of this file on GitHub for full details on how to use filter_var_array().

‡ 4

Uses an external library

String tests is_string() empty() == '' === '' ctype_alpha() ‡1 preg_match (`^[A-Za-z]+$`) preg_match (`^\p{L}+$`u) ctype_alnum() ‡1 preg_match (`^[A-Za-z0-9]+$`) preg_match (`^\w+$`) preg_match (`^\w+$`u) ‡2 preg_match (`^[\p{L}\p{N}]+$`u) strlen() count_chars (…) mb_strlen() $x{2} trim() String tests
String tests is_string() empty() == '' === '' ctype_alpha() ‡1 preg_match (`^[A-Za-z]+$`) preg_match (`^\p{L}+$`u) ctype_alnum() ‡1 preg_match (`^[A-Za-z0-9]+$`) preg_match (`^\w+$`) preg_match (`^\w+$`u) ‡2 preg_match (`^[\p{L}\p{N}]+$`u) strlen() count_chars (…) mb_strlen() $x{2} trim() String tests
$x = null : ( = NULL )
false true true false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 0 0
0 null ‘’
$x = null : ( = NULL )
$x = null : ( = NULL )
false true true false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 0 0
0 null ‘’
$x = null : ( = NULL )
$x = bool : ( = false )
false true true false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 0 0
0 null ‘’
$x = bool : ( = false )
$x = bool : 1 ( = true )
false false false false false false E: not available (PHP 5.1+) false true true true E: not available (PHP 5.1+) 1 1
1 null ‘1’
$x = bool : 1 ( = true )
$x = int : 1
false false false false false false E: not available (PHP 5.1+) false true true true E: not available (PHP 5.1+) 1 1
1 null ‘1’
$x = int : 1
$x = int : 0
false true true false false false E: not available (PHP 5.1+) false true true true E: not available (PHP 5.1+) 1 1
1 null ‘0’
$x = int : 0
$x = int : -1
false false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 2 2
2 null ‘-1’
$x = int : -1
$x = int : 42
false false false false false false E: not available (PHP 5.1+) false true true true E: not available (PHP 5.1+) 2 2
2 null ‘42’
$x = int : 42
†i8$x = int : 13369593
false false false false false false E: not available (PHP 5.1+) true true true true E: not available (PHP 5.1+) 8 8
8 null ‘13369593’
†i8$x = int : 13369593
†i9$x = int : 42
false false false false false false E: not available (PHP 5.1+) false true true true E: not available (PHP 5.1+) 2 2
2 null ‘42’
†i9$x = int : 42
$x = float : 1.3
false false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 3 3
3 null ‘1.3’
$x = float : 1.3
$x = float : 0.005
false false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 5 5
5 null ‘0.005’
$x = float : 0.005
$x = float : 0
false true true false false false E: not available (PHP 5.1+) false true true true E: not available (PHP 5.1+) 1 1
1 null ‘0’
$x = float : 0
$x = float : -1.3
false false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 4 4
4 null ‘-1.3’
$x = float : -1.3
†f5$x = float : -1.#IND
false true true false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 7 7
7 null ‘-1.#IND’
†f5$x = float : -1.#IND
†f6$x = float : 0
false true true false false false E: not available (PHP 5.1+) false true true true E: not available (PHP 5.1+) 1 1
1 null ‘0’
†f6$x = float : 0
†f7$x = float : -1.#INF
false false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 7 7
7 null ‘-1.#INF’
†f7$x = float : -1.#INF
†f9$x = float : 123450000
false false false false false false E: not available (PHP 5.1+) false true true true E: not available (PHP 5.1+) 9 9
9 null ‘123450000’
†f9$x = float : 123450000
$x = string[0] : ‘’
true true true true true false E: not available (PHP 5.1+) true false false false E: not available (PHP 5.1+) 0 0
0 ‘’

#2 )
‘’
$x = string[0] : ‘’
$x = string[1] : ‘ ’
true false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 1 1
1 ‘’

#2 )
‘’
$x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
true false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 2 2
2 ‘’

#2 )
‘1’
$x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
true false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 3 3
3 ‘ ’
‘3’
$x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
true false false false false false E: not available (PHP 5.1+) true true true true E: not available (PHP 5.1+) 1 1
1 ‘’

#2 )
‘1’
$x = string[1] : ‘1’
$x = string[1] : ‘0’
true true false false false false E: not available (PHP 5.1+) true true true true E: not available (PHP 5.1+) 1 1
1 ‘’

#2 )
‘0’
$x = string[1] : ‘0’
$x = string[2] : ‘-1’
true false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 2 2
2 ‘’

#2 )
‘-1’
$x = string[2] : ‘-1’
$x = string[2] : ‘42’
true false false false false false E: not available (PHP 5.1+) true true true true E: not available (PHP 5.1+) 2 2
2 ‘’

#2 )
‘42’
$x = string[2] : ‘42’
$x = string[3] : ‘1.3’
true false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 3 3
3 ‘3’
‘1.3’
$x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
true false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 3 3
3 ‘0’
‘0.0’
$x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
true false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 6 6
6 ‘.’
‘-1.305’
$x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
true false false false true true E: not available (PHP 5.1+) true true true true E: not available (PHP 5.1+) 4 4
4 ‘u’
‘true’
$x = string[4] : ‘true’
$x = string[5] : ‘false’
true false false false true true E: not available (PHP 5.1+) true true true true E: not available (PHP 5.1+) 5 5
5 ‘l’
‘false’
$x = string[5] : ‘false’
$x = string[4] : ‘null’
true false false false true true E: not available (PHP 5.1+) true true true true E: not available (PHP 5.1+) 4 4
4 ‘l’
‘null’
$x = string[4] : ‘null’
$x = string[6] : ‘123str’
true false false false false false E: not available (PHP 5.1+) true true true true E: not available (PHP 5.1+) 6 6
6 ‘3’
‘123str’
$x = string[6] : ‘123str’
$x = string[6] : ‘str123’
true false false false false false E: not available (PHP 5.1+) true true true true E: not available (PHP 5.1+) 6 6
6 ‘r’
‘str123’
$x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
true false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 10 10
10 ‘3’
‘123, "str"’
$x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
true false false false false false E: not available (PHP 5.1+) true true true true E: not available (PHP 5.1+) 8 8
8 ‘C’
‘0xCC00F9’
$x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
true false false false false false E: not available (PHP 5.1+) true true true true E: not available (PHP 5.1+) 4 4
4 ‘2’
‘0123’
$x = string[4] : ‘0123’
$x = string[27] : ‘Iñtërnâtiônàlizætiøn’
true false false false false false E: not available (PHP 5.1+) false false false false E: not available (PHP 5.1+) 27 27
20 ‘±’
‘Iñtërnâtiônàlizætiøn’
$x = string[27] : ‘Iñtërnâtiônàlizætiøn’
$x = array()
false true false false false Error
#3 )
E: not available (PHP 5.1+) false Error
#3 )
Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) 5
#4 )
5

#4 )
false
#5 )
null
#6 )
‘Array’

#4 )
$x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
false false false false false Error
#3 )
E: not available (PHP 5.1+) false Error
#3 )
Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) 5
#4 )
5

#4 )
false
#5 )
null
#6 )
‘Array’

#4 )
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
false false false false false Error
#3 )
E: not available (PHP 5.1+) false Error
#3 )
Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) 5
#4 )
5

#4 )
false
#5 )
1.3
‘Array’

#4 )
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
false true false false false Error
#3 )
E: not available (PHP 5.1+) false Error
#3 )
Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) 6
#7 )
6

#7 )
false
#5 )

Fatal error ( #8 )
‘Object’

#7 )
$x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
false false false false false Error
#3 )
E: not available (PHP 5.1+) false Error
#3 )
Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) 6
#7 )
6

#7 )
false
#5 )

Fatal error ( #8 )
‘Object’

#7 )
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #261 ( = RESOURCE )
false false false false false Error
#3 )
E: not available (PHP 5.1+) false Error
#3 )
Error
#3 )
Error
#3 )
E: not available (PHP 5.1+) 16 16
16 null ‘Resource id #261’
$x = resource : Resource id #261 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Notice: Uninitialized string offset: 2
  3. Warning: preg_match() expects parameter 2 to be string, array/object/resource given
  4. Notice: Array to string conversion
  5. Notice: mb_strlen() [function.mb-strlen]: arg1 is invalid.
  6. Notice: Undefined offset: 2
  7. Notice: Object to string conversion
  8. Fatal error: Cannot use object of type stdClass/TestObject/TestObjectToString as array
‡ 1

Important: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).
In any other case, integers are interpreted as a string containing the decimal digits of the integer.

‡ 2

What \w matches is locale dependent. The locale for these cheatsheets are set to C. Results with other locales will vary.

Array casting settype ( $copy, 'array' ) (array) CastToType::_array ( $x, false ) ‡1 Array casting
Array casting settype ( $copy, 'array' ) (array) CastToType::_array ( $x, false ) ‡1 Array casting
$x = null : ( = NULL )
array()
array()
null $x = null : ( = NULL )
$x = null : ( = NULL )
array()
array()
null $x = null : ( = NULL )
$x = bool : ( = false )
Array: (
  [0] => b false
)
Array: (
  [0] => b false
)
Array: (
  [0] => b false
)
$x = bool : ( = false )
$x = bool : 1 ( = true )
Array: (
  [0] => b true
)
Array: (
  [0] => b true
)
Array: (
  [0] => b true
)
$x = bool : 1 ( = true )
$x = int : 1
Array: (
  [0] => 1
)
Array: (
  [0] => 1
)
Array: (
  [0] => 1
)
$x = int : 1
$x = int : 0
Array: (
  [0] => 0
)
Array: (
  [0] => 0
)
Array: (
  [0] => 0
)
$x = int : 0
$x = int : -1
Array: (
  [0] => -1
)
Array: (
  [0] => -1
)
Array: (
  [0] => -1
)
$x = int : -1
$x = int : 42
Array: (
  [0] => 42
)
Array: (
  [0] => 42
)
Array: (
  [0] => 42
)
$x = int : 42
†i8$x = int : 13369593
Array: (
  [0] => 13369593
)
Array: (
  [0] => 13369593
)
Array: (
  [0] => 13369593
)
†i8$x = int : 13369593
†i9$x = int : 42
Array: (
  [0] => 42
)
Array: (
  [0] => 42
)
Array: (
  [0] => 42
)
†i9$x = int : 42
$x = float : 1.3
Array: (
  [0] => 1.3
)
Array: (
  [0] => 1.3
)
Array: (
  [0] => 1.3
)
$x = float : 1.3
$x = float : 0.005
Array: (
  [0] => 0.005
)
Array: (
  [0] => 0.005
)
Array: (
  [0] => 0.005
)
$x = float : 0.005
$x = float : 0
Array: (
  [0] => 0
)
Array: (
  [0] => 0
)
Array: (
  [0] => 0
)
$x = float : 0
$x = float : -1.3
Array: (
  [0] => -1.3
)
Array: (
  [0] => -1.3
)
Array: (
  [0] => -1.3
)
$x = float : -1.3
†f5$x = float : -1.#IND
Array: (
  [0] => -1.#IND
)
Array: (
  [0] => -1.#IND
)
Array: (
  [0] => -1.#IND
)
†f5$x = float : -1.#IND
†f6$x = float : 0
Array: (
  [0] => 0
)
Array: (
  [0] => 0
)
Array: (
  [0] => 0
)
†f6$x = float : 0
†f7$x = float : -1.#INF
Array: (
  [0] => -1.#INF
)
Array: (
  [0] => -1.#INF
)
Array: (
  [0] => -1.#INF
)
†f7$x = float : -1.#INF
†f9$x = float : 123450000
Array: (
  [0] => 123450000
)
Array: (
  [0] => 123450000
)
Array: (
  [0] => 123450000
)
†f9$x = float : 123450000
$x = string[0] : ‘’
Array: (
  [0] => ‘’
)
Array: (
  [0] => ‘’
)
Array: (
  [0] => ‘’
)
$x = string[0] : ‘’
$x = string[1] : ‘ ’
Array: (
  [0] => ‘ ’
)
Array: (
  [0] => ‘ ’
)
Array: (
  [0] => ‘ ’
)
$x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
Array: (
  [0] => ‘ 1’
)
Array: (
  [0] => ‘ 1’
)
Array: (
  [0] => ‘ 1’
)
$x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
Array: (
  [0] => ‘ 3 ’
)
Array: (
  [0] => ‘ 3 ’
)
Array: (
  [0] => ‘ 3 ’
)
$x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
Array: (
  [0] => ‘1’
)
Array: (
  [0] => ‘1’
)
Array: (
  [0] => ‘1’
)
$x = string[1] : ‘1’
$x = string[1] : ‘0’
Array: (
  [0] => ‘0’
)
Array: (
  [0] => ‘0’
)
Array: (
  [0] => ‘0’
)
$x = string[1] : ‘0’
$x = string[2] : ‘-1’
Array: (
  [0] => ‘-1’
)
Array: (
  [0] => ‘-1’
)
Array: (
  [0] => ‘-1’
)
$x = string[2] : ‘-1’
$x = string[2] : ‘42’
Array: (
  [0] => ‘42’
)
Array: (
  [0] => ‘42’
)
Array: (
  [0] => ‘42’
)
$x = string[2] : ‘42’
$x = string[3] : ‘1.3’
Array: (
  [0] => ‘1.3’
)
Array: (
  [0] => ‘1.3’
)
Array: (
  [0] => ‘1.3’
)
$x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
Array: (
  [0] => ‘0.0’
)
Array: (
  [0] => ‘0.0’
)
Array: (
  [0] => ‘0.0’
)
$x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
Array: (
  [0] => ‘-1.305’
)
Array: (
  [0] => ‘-1.305’
)
Array: (
  [0] => ‘-1.305’
)
$x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
Array: (
  [0] => ‘true’
)
Array: (
  [0] => ‘true’
)
Array: (
  [0] => ‘true’
)
$x = string[4] : ‘true’
$x = string[5] : ‘false’
Array: (
  [0] => ‘false’
)
Array: (
  [0] => ‘false’
)
Array: (
  [0] => ‘false’
)
$x = string[5] : ‘false’
$x = string[4] : ‘null’
Array: (
  [0] => ‘null’
)
Array: (
  [0] => ‘null’
)
Array: (
  [0] => ‘null’
)
$x = string[4] : ‘null’
$x = string[6] : ‘123str’
Array: (
  [0] => ‘123str’
)
Array: (
  [0] => ‘123str’
)
Array: (
  [0] => ‘123str’
)
$x = string[6] : ‘123str’
$x = string[6] : ‘str123’
Array: (
  [0] => ‘str123’
)
Array: (
  [0] => ‘str123’
)
Array: (
  [0] => ‘str123’
)
$x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
Array: (
  [0] => ‘123, "str"’
)
Array: (
  [0] => ‘123, "str"’
)
Array: (
  [0] => ‘123, "str"’
)
$x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
Array: (
  [0] => ‘0xCC00F9’
)
Array: (
  [0] => ‘0xCC00F9’
)
Array: (
  [0] => ‘0xCC00F9’
)
$x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
Array: (
  [0] => ‘0123’
)
Array: (
  [0] => ‘0123’
)
Array: (
  [0] => ‘0123’
)
$x = string[4] : ‘0123’
$x = array()
array()
array()
null $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
Array: (
  [1] => ‘string’
)
Array: (
  [1] => ‘string’
)
Array: (
  [1] => ‘string’
)
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
array()
array()
null $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
Array: (
  [test1] => null
  [test2] => b true
  [test3] => ‘some string’
)
Array: (
  [test1] => null
  [test2] => b true
  [test3] => ‘some string’
)
Array: (
  [test1] => null
  [test2] => b true
  [test3] => ‘some string’
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #264 ( = RESOURCE )
Array: (
  [0] => Resource id #264
)
Array: (
  [0] => Resource id #264
)
Array: (
  [0] => Resource id #264
)
$x = resource : Resource id #264 ( = RESOURCE )
  1. Notice: Undefined index: notset
‡ 1

Uses an external library

Array testing is_array() count() empty() count() > 0 isset ( $x[0] ) ‡1 array_key_exists ( 0, $x ) ‡1 isset ( $x['foo'] ) ‡1 key() current() $x['foo'] $x['foo']['bar'] array_filter() Array testing
Array testing is_array() count() empty() count() > 0 isset ( $x[0] ) ‡1 array_key_exists ( 0, $x ) ‡1 isset ( $x['foo'] ) ‡1 key() current() $x['foo'] $x['foo']['bar'] array_filter() Array testing
$x = null : ( = NULL )
false 0 true false false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = null : ( = NULL )
$x = null : ( = NULL )
false 0 true false false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = null : ( = NULL )
$x = bool : ( = false )
false 1 true true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = bool : ( = false )
$x = bool : 1 ( = true )
false 1 false true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = bool : 1 ( = true )
$x = int : 1
false 1 false true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = int : 1
$x = int : 0
false 1 true true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = int : 0
$x = int : -1
false 1 false true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = int : -1
$x = int : 42
false 1 false true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = int : 42
†i8$x = int : 13369593
false 1 false true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
†i8$x = int : 13369593
†i9$x = int : 42
false 1 false true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
†i9$x = int : 42
$x = float : 1.3
false 1 false true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = float : 1.3
$x = float : 0.005
false 1 false true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = float : 0.005
$x = float : 0
false 1 true true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = float : 0
$x = float : -1.3
false 1 false true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = float : -1.3
†f5$x = float : -1.#IND
false 1 true true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
†f5$x = float : -1.#IND
†f6$x = float : 0
false 1 true true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
†f6$x = float : 0
†f7$x = float : -1.#INF
false 1 false true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
†f7$x = float : -1.#INF
†f9$x = float : 123450000
false 1 false true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
†f9$x = float : 123450000
$x = string[0] : ‘’
false 1 true true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
‘’

#6 )
null null
#5 )
$x = string[0] : ‘’
$x = string[1] : ‘ ’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘ ’
null null
#5 )
$x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘ ’
null null
#5 )
$x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘ ’
null null
#5 )
$x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘1’
null null
#5 )
$x = string[1] : ‘1’
$x = string[1] : ‘0’
false 1 true true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘0’
null null
#5 )
$x = string[1] : ‘0’
$x = string[2] : ‘-1’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘-’
null null
#5 )
$x = string[2] : ‘-1’
$x = string[2] : ‘42’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘4’
null null
#5 )
$x = string[2] : ‘42’
$x = string[3] : ‘1.3’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘1’
null null
#5 )
$x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘0’
null null
#5 )
$x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘-’
null null
#5 )
$x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘t’
null null
#5 )
$x = string[4] : ‘true’
$x = string[5] : ‘false’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘f’
null null
#5 )
$x = string[5] : ‘false’
$x = string[4] : ‘null’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘n’
null null
#5 )
$x = string[4] : ‘null’
$x = string[6] : ‘123str’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘1’
null null
#5 )
$x = string[6] : ‘123str’
$x = string[6] : ‘str123’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘s’
null null
#5 )
$x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘1’
null null
#5 )
$x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘0’
null null
#5 )
$x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
false 1 false true true false
#2 )
#2 )
true b false

#3 )
b false

#4 )
‘0’
null null
#5 )
$x = string[4] : ‘0123’
$x = array()
true 0 true false false false false null b false
null
#7 )
null
#7 )
array()
$x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
true 1 false true false false false 1
‘string’
null
#7 )
null
#7 )
Array: (
  [1] => ‘string’
)
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
true 6 false true true true false 0
b false
null
#7 )
null
#7 )
Array: (
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
false 1 true true
Fatal error ( #8 )
false
Fatal error ( #8 )
null b false

Fatal error ( #8 )

Fatal error ( #8 )
null
#5 )
$x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobject (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: print_it
    )
)
false 1 false true
Fatal error ( #8 )
false
Fatal error ( #8 )
‘test1’
null
Fatal error ( #8 )

Fatal error ( #8 )
null
#5 )
$x = Object: (
    Class: testobject (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: print_it
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
false 1 false true
Fatal error ( #8 )
false
Fatal error ( #8 )
‘test1’
null
Fatal error ( #8 )

Fatal error ( #8 )
null
#5 )
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #310 ( = RESOURCE )
false 1 false true false false
#2 )
#2 )
false b false

#3 )
b false

#4 )
null null null
#5 )
$x = resource : Resource id #310 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object
  3. Warning: key() [function.key]: Passed variable is not an array or object
  4. Warning: current() [function.current]: Passed variable is not an array or object
  5. Warning: array_filter() [function.array-filter]: The first argument should be an array
  6. Notice: Uninitialized string offset: 0
  7. Notice: Undefined index: foo
  8. Fatal error: Cannot use object of type stdClass/TestObject/TestObjectToString as array
‡ 1

Whether to use isset() or array_key_exists() depends on what you want to know:

  • isset( $array[$key] ) will tell you whether the array key exists and has been assigned a value.
    Used on its own it will give undesired results when used on strings as characters within a string can be approached using the $x[] syntax as well.
    Also, it will cause fatal errors when used on objects.
  • array_key_exists( $key, $array ) will tell you only whether the array key exists, but will not check whether it has a value assigned to it.
    Used on its own, it will show a warning if $array is not an array

This said, we can concluded that to avoid warnings and undesired results you will always have to use an is_array() first.
Also note that isset() is faster than array_key_exists(), but as said above, will return false if no value has been assigned.

Objects settype ( $copy, 'object' ) (object) CastToType::_object ( $x, false ) ‡1 is_object() is_a ( $x, 'TestObject' ) instanceof TestObject get_class() get_parent_class() is_subclass_of ( $x, 'TestObject' ) Objects
Objects settype ( $copy, 'object' ) (object) CastToType::_object ( $x, false ) ‡1 is_object() is_a ( $x, 'TestObject' ) instanceof TestObject get_class() get_parent_class() is_subclass_of ( $x, 'TestObject' ) Objects
$x = null : ( = NULL )
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
null false false E: not available (PHP 5.0+) false false false $x = null : ( = NULL )
$x = null : ( = NULL )
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
null false false E: not available (PHP 5.0+) false false false $x = null : ( = NULL )
$x = bool : ( = false )
Object: (
  Class: stdClass (
    property: scalar = b false
  )
)
Object: (
  Class: stdClass (
    property: scalar = b false
  )
)
Object: (
  Class: stdClass (
    property: scalar = b false
  )
)
false false E: not available (PHP 5.0+) false false false $x = bool : ( = false )
$x = bool : 1 ( = true )
Object: (
  Class: stdClass (
    property: scalar = b true
  )
)
Object: (
  Class: stdClass (
    property: scalar = b true
  )
)
Object: (
  Class: stdClass (
    property: scalar = b true
  )
)
false false E: not available (PHP 5.0+) false false false $x = bool : 1 ( = true )
$x = int : 1
Object: (
  Class: stdClass (
    property: scalar = 1
  )
)
Object: (
  Class: stdClass (
    property: scalar = 1
  )
)
Object: (
  Class: stdClass (
    property: scalar = 1
  )
)
false false E: not available (PHP 5.0+) false false false $x = int : 1
$x = int : 0
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
false false E: not available (PHP 5.0+) false false false $x = int : 0
$x = int : -1
Object: (
  Class: stdClass (
    property: scalar = -1
  )
)
Object: (
  Class: stdClass (
    property: scalar = -1
  )
)
Object: (
  Class: stdClass (
    property: scalar = -1
  )
)
false false E: not available (PHP 5.0+) false false false $x = int : -1
$x = int : 42
Object: (
  Class: stdClass (
    property: scalar = 42
  )
)
Object: (
  Class: stdClass (
    property: scalar = 42
  )
)
Object: (
  Class: stdClass (
    property: scalar = 42
  )
)
false false E: not available (PHP 5.0+) false false false $x = int : 42
†i8$x = int : 13369593
Object: (
  Class: stdClass (
    property: scalar = 13369593
  )
)
Object: (
  Class: stdClass (
    property: scalar = 13369593
  )
)
Object: (
  Class: stdClass (
    property: scalar = 13369593
  )
)
false false E: not available (PHP 5.0+) false false false †i8$x = int : 13369593
†i9$x = int : 42
Object: (
  Class: stdClass (
    property: scalar = 42
  )
)
Object: (
  Class: stdClass (
    property: scalar = 42
  )
)
Object: (
  Class: stdClass (
    property: scalar = 42
  )
)
false false E: not available (PHP 5.0+) false false false †i9$x = int : 42
$x = float : 1.3
Object: (
  Class: stdClass (
    property: scalar = 1.3
  )
)
Object: (
  Class: stdClass (
    property: scalar = 1.3
  )
)
Object: (
  Class: stdClass (
    property: scalar = 1.3
  )
)
false false E: not available (PHP 5.0+) false false false $x = float : 1.3
$x = float : 0.005
Object: (
  Class: stdClass (
    property: scalar = 0.005
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0.005
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0.005
  )
)
false false E: not available (PHP 5.0+) false false false $x = float : 0.005
$x = float : 0
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
false false E: not available (PHP 5.0+) false false false $x = float : 0
$x = float : -1.3
Object: (
  Class: stdClass (
    property: scalar = -1.3
  )
)
Object: (
  Class: stdClass (
    property: scalar = -1.3
  )
)
Object: (
  Class: stdClass (
    property: scalar = -1.3
  )
)
false false E: not available (PHP 5.0+) false false false $x = float : -1.3
†f5$x = float : -1.#IND
Object: (
  Class: stdClass (
    property: scalar = -1.#IND
  )
)
Object: (
  Class: stdClass (
    property: scalar = -1.#IND
  )
)
Object: (
  Class: stdClass (
    property: scalar = -1.#IND
  )
)
false false E: not available (PHP 5.0+) false false false †f5$x = float : -1.#IND
†f6$x = float : 0
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
false false E: not available (PHP 5.0+) false false false †f6$x = float : 0
†f7$x = float : -1.#INF
Object: (
  Class: stdClass (
    property: scalar = -1.#INF
  )
)
Object: (
  Class: stdClass (
    property: scalar = -1.#INF
  )
)
Object: (
  Class: stdClass (
    property: scalar = -1.#INF
  )
)
false false E: not available (PHP 5.0+) false false false †f7$x = float : -1.#INF
†f9$x = float : 123450000
Object: (
  Class: stdClass (
    property: scalar = 123450000
  )
)
Object: (
  Class: stdClass (
    property: scalar = 123450000
  )
)
Object: (
  Class: stdClass (
    property: scalar = 123450000
  )
)
false false E: not available (PHP 5.0+) false false false †f9$x = float : 123450000
$x = string[0] : ‘’
Object: (
  Class: stdClass (
    property: scalar = ‘’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘’
  )
)
null false false E: not available (PHP 5.0+) false false false $x = string[0] : ‘’
$x = string[1] : ‘ ’
Object: (
  Class: stdClass (
    property: scalar = ‘ ’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘ ’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘ ’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
Object: (
  Class: stdClass (
    property: scalar = ‘ 1’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘ 1’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘ 1’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
Object: (
  Class: stdClass (
    property: scalar = ‘ 3 ’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘ 3 ’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘ 3 ’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
Object: (
  Class: stdClass (
    property: scalar = ‘1’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘1’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘1’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[1] : ‘1’
$x = string[1] : ‘0’
Object: (
  Class: stdClass (
    property: scalar = ‘0’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[1] : ‘0’
$x = string[2] : ‘-1’
Object: (
  Class: stdClass (
    property: scalar = ‘-1’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘-1’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘-1’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[2] : ‘-1’
$x = string[2] : ‘42’
Object: (
  Class: stdClass (
    property: scalar = ‘42’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘42’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘42’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
Object: (
  Class: stdClass (
    property: scalar = ‘1.3’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘1.3’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘1.3’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
Object: (
  Class: stdClass (
    property: scalar = ‘0.0’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0.0’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0.0’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
Object: (
  Class: stdClass (
    property: scalar = ‘-1.305’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘-1.305’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘-1.305’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
Object: (
  Class: stdClass (
    property: scalar = ‘true’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘true’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘true’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[4] : ‘true’
$x = string[5] : ‘false’
Object: (
  Class: stdClass (
    property: scalar = ‘false’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘false’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘false’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[5] : ‘false’
$x = string[4] : ‘null’
Object: (
  Class: stdClass (
    property: scalar = ‘null’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘null’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘null’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[4] : ‘null’
$x = string[6] : ‘123str’
Object: (
  Class: stdClass (
    property: scalar = ‘123str’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘123str’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘123str’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
Object: (
  Class: stdClass (
    property: scalar = ‘str123’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘str123’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘str123’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
Object: (
  Class: stdClass (
    property: scalar = ‘123, "str"’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘123, "str"’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘123, "str"’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
Object: (
  Class: stdClass (
    property: scalar = ‘0xCC00F9’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0xCC00F9’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0xCC00F9’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
Object: (
  Class: stdClass (
    property: scalar = ‘0123’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0123’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0123’
  )
)
false false E: not available (PHP 5.0+) false false false $x = string[4] : ‘0123’
$x = array()
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
null false false E: not available (PHP 5.0+) false false false $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
Object: (
  Class: stdClass (
    property: 1 = ‘string’
  )
)
Object: (
  Class: stdClass (
    property: 1 = ‘string’
  )
)
Object: (
  Class: stdClass (
    property: 1 = ‘string’
  )
)
false false E: not available (PHP 5.0+) false false false $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
Object: (
  Class: stdClass (
    property: 0 = b false
    property: 1 = 1
    property: 2 = 1.3
    property: 3 = ‘123str’
    property: 4 = ‘str123’
    property: 5 = null   )
)
Object: (
  Class: stdClass (
    property: 0 = b false
    property: 1 = 1
    property: 2 = 1.3
    property: 3 = ‘123str’
    property: 4 = ‘str123’
    property: 5 = null   )
)
Object: (
  Class: stdClass (
    property: 0 = b false
    property: 1 = 1
    property: 2 = 1.3
    property: 3 = ‘123str’
    property: 4 = ‘str123’
    property: 5 = null   )
)
false false E: not available (PHP 5.0+) false false false $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Array: (
    [s (string)] => string[6] : ‘simple’
    [m (string)] => Array:     (
        [0 (int)] => string[5] : ‘test1’
        [1 (int)] => string[5] : ‘test2’
    )
)
Object: (
  Class: stdClass (
    property: s = ‘simple’
    property: m (array) Array:     (
      [0] => ‘test1’
      [1] => ‘test2’
    )
  )
)
Object: (
  Class: stdClass (
    property: s = ‘simple’
    property: m (array) Array:     (
      [0] => ‘test1’
      [1] => ‘test2’
    )
  )
)
Object: (
  Class: stdClass (
    property: s = ‘simple’
    property: m (array) Array:     (
      [0] => ‘test1’
      [1] => ‘test2’
    )
  )
)
false false E: not available (PHP 5.0+) false false false $x = Array: (
    [s (string)] => string[6] : ‘simple’
    [m (string)] => Array:     (
        [0 (int)] => string[5] : ‘test1’
        [1 (int)] => string[5] : ‘test2’
    )
)
$x = Object: (
    Class: stdClass (
    )
)
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
null true false E: not available (PHP 5.0+) ‘stdClass’
false false $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobject (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: print_it
    )
)
Object: (
  Class: testobject (
    property: test1 = null     property: test2 = b true
    method: print_it
  )
)
Object: (
  Class: testobject (
    property: test1 = null     property: test2 = b true
    method: print_it
  )
)
Object: (
  Class: testobject (
    property: test1 = null     property: test2 = b true
    method: print_it
  )
)
true true E: not available (PHP 5.0+) ‘testobject’
false false $x = Object: (
    Class: testobject (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: print_it
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
Object: (
  Class: testobjecttostring (
    property: test1 = null     property: test2 = b true
    property: test3 = ‘some string’
    method: print_it
    method: __tostring
  )
)
Object: (
  Class: testobjecttostring (
    property: test1 = null     property: test2 = b true
    property: test3 = ‘some string’
    method: print_it
    method: __tostring
  )
)
Object: (
  Class: testobjecttostring (
    property: test1 = null     property: test2 = b true
    property: test3 = ‘some string’
    method: print_it
    method: __tostring
  )
)
true true E: not available (PHP 5.0+) ‘testobjecttostring’
‘testobject’
true $x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #313 ( = RESOURCE )
Object: (
  Class: stdClass (
    property: scalar = Resource id #313
  )
)
Object: (
  Class: stdClass (
    property: scalar = Resource id #313
  )
)
Object: (
  Class: stdClass (
    property: scalar = Resource id #313
  )
)
false false E: not available (PHP 5.0+) false false false $x = resource : Resource id #313 ( = RESOURCE )
  1. Notice: Undefined index: notset
‡ 1

Uses an external library

Resources is_resource() get_resource_type() Resources
Resources is_resource() get_resource_type() Resources
$x = null : ( = NULL )
false false
#2 )
$x = null : ( = NULL )
$x = null : ( = NULL )
false false
#2 )
$x = null : ( = NULL )
$x = bool : ( = false )
false false
#2 )
$x = bool : ( = false )
$x = bool : 1 ( = true )
false false
#2 )
$x = bool : 1 ( = true )
$x = int : 1
false false
#2 )
$x = int : 1
$x = int : 0
false false
#2 )
$x = int : 0
$x = int : -1
false false
#2 )
$x = int : -1
$x = int : 42
false false
#2 )
$x = int : 42
†i8$x = int : 13369593
false false
#2 )
†i8$x = int : 13369593
†i9$x = int : 42
false false
#2 )
†i9$x = int : 42
$x = float : 1.3
false false
#2 )
$x = float : 1.3
$x = float : 0.005
false false
#2 )
$x = float : 0.005
$x = float : 0
false false
#2 )
$x = float : 0
$x = float : -1.3
false false
#2 )
$x = float : -1.3
†f5$x = float : -1.#IND
false false
#2 )
†f5$x = float : -1.#IND
†f6$x = float : 0
false false
#2 )
†f6$x = float : 0
†f7$x = float : -1.#INF
false false
#2 )
†f7$x = float : -1.#INF
†f9$x = float : 123450000
false false
#2 )
†f9$x = float : 123450000
$x = string[0] : ‘’
false false
#2 )
$x = string[0] : ‘’
$x = string[1] : ‘ ’
false false
#2 )
$x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
false false
#2 )
$x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
false false
#2 )
$x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
false false
#2 )
$x = string[1] : ‘1’
$x = string[1] : ‘0’
false false
#2 )
$x = string[1] : ‘0’
$x = string[2] : ‘-1’
false false
#2 )
$x = string[2] : ‘-1’
$x = string[2] : ‘42’
false false
#2 )
$x = string[2] : ‘42’
$x = string[3] : ‘1.3’
false false
#2 )
$x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
false false
#2 )
$x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
false false
#2 )
$x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
false false
#2 )
$x = string[4] : ‘true’
$x = string[5] : ‘false’
false false
#2 )
$x = string[5] : ‘false’
$x = string[4] : ‘null’
false false
#2 )
$x = string[4] : ‘null’
$x = string[6] : ‘123str’
false false
#2 )
$x = string[6] : ‘123str’
$x = string[6] : ‘str123’
false false
#2 )
$x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
false false
#2 )
$x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
false false
#2 )
$x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
false false
#2 )
$x = string[4] : ‘0123’
$x = array()
false false
#2 )
$x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
false false
#2 )
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
false false
#2 )
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
false false
#2 )
$x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
false false
#2 )
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #361 ( = RESOURCE )
true ‘stream’ $x = resource : Resource id #361 ( = RESOURCE )
$x = resource : Resource id #362 ( = RESOURCE )
true ‘gd’ $x = resource : Resource id #362 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Warning: Supplied argument is not a valid resource handle
Basic Arithmetic $x = ++$x ‡1 $x = $x++ ‡1 $x = --$x ‡1 $x = $x-- ‡1 -$x $x + 0 $x - 0 $x * 1 $x / 1 $x % 1 Basic Arithmetic
Basic Arithmetic $x = ++$x ‡1 $x = $x++ ‡1 $x = --$x ‡1 $x = $x-- ‡1 -$x $x + 0 $x - 0 $x * 1 $x / 1 $x % 1 Basic Arithmetic
$x = null : ( = NULL )
1 null null null 0
0 0
0
0
0
$x = null : ( = NULL )
$x = null : ( = NULL )
1 null null null 0
0 0
0
0
0
$x = null : ( = NULL )
$x = bool : ( = false )
b false
b false
b false
b false
0
0 0
0
0
0
$x = bool : ( = false )
$x = bool : 1 ( = true )
b true
b true
b true
b true
-1
1 1
1
1
0
$x = bool : 1 ( = true )
$x = int : 1
2 1 0 1 -1
1 1
1
1
0
$x = int : 1
$x = int : 0
1 0 -1 0 0
0 0
0
0
0
$x = int : 0
$x = int : -1
0 -1 -2 -1 1
-1 -1
-1
-1
0
$x = int : -1
$x = int : 42
43 42 41 42 -42
42 42
42
42
0
$x = int : 42
†i8$x = int : 13369593
13369594 13369593 13369592 13369593 -13369593
13369593 13369593
13369593
13369593
0
†i8$x = int : 13369593
†i9$x = int : 42
43 42 41 42 -42
42 42
42
42
0
†i9$x = int : 42
$x = float : 1.3
2.3 1.3 0.3 1.3 -1.3
1.3 1.3
1.3
1.3
0
$x = float : 1.3
$x = float : 0.005
1.005 0.005 -0.995 0.005 -0.005
0.005 0.005
0.005
0.005
0
$x = float : 0.005
$x = float : 0
1 0 -1 0 0
0 0
0
0
0
$x = float : 0
$x = float : -1.3
-0.3 -1.3 -2.3 -1.3 1.3
-1.3 -1.3
-1.3
-1.3
0
$x = float : -1.3
†f5$x = float : -1.#IND
-1.#IND -1.#IND -1.#IND -1.#IND -1.#IND
-1.#IND -1.#IND
-1.#IND
-1.#IND
0
†f5$x = float : -1.#IND
†f6$x = float : 0
1 0 -1 0 0
0 0
0
0
0
†f6$x = float : 0
†f7$x = float : -1.#INF
-1.#INF -1.#INF -1.#INF -1.#INF 1.#INF
-1.#INF -1.#INF
-1.#INF
-1.#INF
0
†f7$x = float : -1.#INF
†f9$x = float : 123450000
123450001 123450000 123449999 123450000 -123450000
123450000 123450000
123450000
123450000
0
†f9$x = float : 123450000
$x = string[0] : ‘’
‘1’
‘’
-1 ‘’
0
0 0
0
0
0
$x = string[0] : ‘’
$x = string[1] : ‘ ’
‘ ’
‘ ’
‘ ’
‘ ’
0
0 0
0
0
0
$x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
2 ‘ 1’
0 ‘ 1’
-1
1 1
1
1
0
$x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
‘ 3 ’
‘ 3 ’
‘ 3 ’
‘ 3 ’
-3
3 3
3
3
0
$x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
2 ‘1’
0 ‘1’
-1
1 1
1
1
0
$x = string[1] : ‘1’
$x = string[1] : ‘0’
1 ‘0’
-1 ‘0’
0
0 0
0
0
0
$x = string[1] : ‘0’
$x = string[2] : ‘-1’
0 ‘-1’
-2 ‘-1’
1
-1 -1
-1
-1
0
$x = string[2] : ‘-1’
$x = string[2] : ‘42’
43 ‘42’
41 ‘42’
-42
42 42
42
42
0
$x = string[2] : ‘42’
$x = string[3] : ‘1.3’
2.3 ‘1.3’
0.3 ‘1.3’
-1.3
1.3 1.3
1.3
1.3
0
$x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
1 ‘0.0’
-1 ‘0.0’
0
0 0
0
0
0
$x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
-0.305 ‘-1.305’
-2.305 ‘-1.305’
1.305
-1.305 -1.305
-1.305
-1.305
0
$x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
‘truf’
‘true’
‘true’
‘true’
0
0 0
0
0
0
$x = string[4] : ‘true’
$x = string[5] : ‘false’
‘falsf’
‘false’
‘false’
‘false’
0
0 0
0
0
0
$x = string[5] : ‘false’
$x = string[4] : ‘null’
‘nulm’
‘null’
‘null’
‘null’
0
0 0
0
0
0
$x = string[4] : ‘null’
$x = string[6] : ‘123str’
‘123sts’
‘123str’
‘123str’
‘123str’
-123
123 123
123
123
0
$x = string[6] : ‘123str’
$x = string[6] : ‘str123’
‘str124’
‘str123’
‘str123’
‘str123’
0
0 0
0
0
0
$x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
‘123, "str"’
‘123, "str"’
‘123, "str"’
‘123, "str"’
-123
123 123
123
123
0
$x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
13369594 ‘0xCC00F9’
13369592 ‘0xCC00F9’
-13369593
13369593 13369593
13369593
13369593
0
$x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
124 ‘0123’
122 ‘0123’
-123
123 123
123
123
0
$x = string[4] : ‘0123’
$x = array()
array()
array()
array()
array()

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )
0
$x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
Array: (
  [1] => ‘string’
)
Array: (
  [1] => ‘string’
)
Array: (
  [1] => ‘string’
)
Array: (
  [1] => ‘string’
)

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )
0
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )
0
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )
0
$x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
Object: (
  Class: testobjecttostring (
    property: test1 = null     property: test2 = b true
    property: test3 = ‘some string’
    method: print_it
    method: __tostring
  )
)
Object: (
  Class: testobjecttostring (
    property: test1 = null     property: test2 = b true
    property: test3 = ‘some string’
    method: print_it
    method: __tostring
  )
)
Object: (
  Class: testobjecttostring (
    property: test1 = null     property: test2 = b true
    property: test3 = ‘some string’
    method: print_it
    method: __tostring
  )
)
Object: (
  Class: testobjecttostring (
    property: test1 = null     property: test2 = b true
    property: test3 = ‘some string’
    method: print_it
    method: __tostring
  )
)

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )
0
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #364 ( = RESOURCE )
Resource id #364
Resource id #364
Resource id #364
Resource id #364
-364
364 364
364
364
0
$x = resource : Resource id #364 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Fatal error: Unsupported operand types
‡ 1

Please take note: using the in-/decrementors on SplInt and SplFloat objects may give unexpected (inconsistent) results....

CType Extension ctype_digit() ‡1 ctype_xdigit() ‡1 ctype_alpha() ‡1 ctype_alnum() ‡1 ctype_graph() ‡1 ctype_print() ‡1 ctype_lower() ‡1 ctype_upper() ‡1 ctype_cntrl() ‡1 ctype_punct() ‡1 ctype_space() ‡1 CType Extension
CType Extension ctype_digit() ‡1 ctype_xdigit() ‡1 ctype_alpha() ‡1 ctype_alnum() ‡1 ctype_graph() ‡1 ctype_print() ‡1 ctype_lower() ‡1 ctype_upper() ‡1 ctype_cntrl() ‡1 ctype_punct() ‡1 ctype_space() ‡1 CType Extension
$x = null : ( = NULL )
false false false false false false false false false false false $x = null : ( = NULL )
$x = null : ( = NULL )
false false false false false false false false false false false $x = null : ( = NULL )
$x = bool : ( = false )
false false false false false false false false false false false $x = bool : ( = false )
$x = bool : 1 ( = true )
false false false false false false false false false false false $x = bool : 1 ( = true )
$x = int : 1
false false false false false false false false true false false $x = int : 1
$x = int : 0
false false false false false false false false true false false $x = int : 0
$x = int : -1
false false false false false false false false false false false $x = int : -1
$x = int : 10
false false false false false false false false true false true $x = int : 10
$x = int : 42
false false false false true true false false false true false $x = int : 42
$x = int : 111
false false true true true true true false false false false $x = int : 111
$x = int : 12345
true true false true true false false false false false false $x = int : 12345
†i8$x = int : 13369593
true true false true true false false false false false false †i8$x = int : 13369593
†i9$x = int : 42
false false false false true true false false false true false †i9$x = int : 42
$x = float : 1.3
false false false false false false false false false false false $x = float : 1.3
$x = float : 0.005
false false false false false false false false false false false $x = float : 0.005
$x = float : 0
false false false false false false false false false false false $x = float : 0
$x = float : -1.3
false false false false false false false false false false false $x = float : -1.3
†f5$x = float : -1.#IND
false false false false false false false false false false false †f5$x = float : -1.#IND
†f6$x = float : 0
false false false false false false false false false false false †f6$x = float : 0
†f7$x = float : -1.#INF
false false false false false false false false false false false †f7$x = float : -1.#INF
†f9$x = float : 123450000
false false false false false false false false false false false †f9$x = float : 123450000
$x = string[0] : ‘’
true true true true true true true true true true true $x = string[0] : ‘’
$x = string[1] : ‘ ’
false false false false false true false false false false true $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
false false false false false true false false false false false $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
false false false false false true false false false false false $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
true true false true true true false false false false false $x = string[1] : ‘1’
$x = string[1] : ‘0’
true true false true true true false false false false false $x = string[1] : ‘0’
$x = string[2] : ‘-1’
false false false false true true false false false false false $x = string[2] : ‘-1’
$x = string[2] : ‘42’
true true false true true true false false false false false $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
false false false false true true false false false false false $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
false false false false true true false false false false false $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
false false false false true true false false false false false $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
false false true true true true true false false false false $x = string[4] : ‘true’
$x = string[5] : ‘false’
false false true true true true true false false false false $x = string[5] : ‘false’
$x = string[4] : ‘null’
false false true true true true true false false false false $x = string[4] : ‘null’
$x = string[6] : ‘123str’
false false false true true true false false false false false $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
false false false true true true false false false false false $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
false false false false false true false false false false false $x = string[10] : ‘123, "str"’
$x = string[9] : ‘123,"str"’
false false false false true true false false false false false $x = string[9] : ‘123,"str"’
†sk$x = string[12] : ‘123, "str" ’
false false false false false false false false false false false †sk$x = string[12] : ‘123, "str" ’
$x = string[6] : ‘AF036C’
false true false true true true false false false false false $x = string[6] : ‘AF036C’
$x = string[3] : ‘FOO’
false false true true true true false true false false false $x = string[3] : ‘FOO’
†sn$x = string[5] : ‘\f ’
false false false false false false false false false false false †sn$x = string[5] : ‘\f ’
$x = string[5] : ‘*&$()’
false false false false true true false false false true false $x = string[5] : ‘*&$()’
†sp$x = string[4] : ‘ ’
false false false false false false false false true false false †sp$x = string[4] : ‘ ’
$x = string[8] : ‘0xCC00F9’
false false false true true true false false false false false $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
true true false true true true false false false false false $x = string[4] : ‘0123’
$x = string[27] : ‘Iñtërnâtiônàlizætiøn’
false false false false false false false false false false false $x = string[27] : ‘Iñtërnâtiônàlizætiøn’
$x = array()
false false false false false false false false false false false $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
false false false false false false false false false false false $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
false false false false false false false false false false false $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
false false false false false false false false false false false $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
false false false false false false false false false false false $x = Object: (
    Class: testobjecttostring (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        property: test3 = string[11] : ‘some string’
        method: print_it
        method: __tostring
    )
)
$x = resource : Resource id #367 ( = RESOURCE )
false false false false false false false false false false false $x = resource : Resource id #367 ( = RESOURCE )
  1. Notice: Undefined index: notset
‡ 1

Important: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).
In any other case, integers are interpreted as a string containing the decimal digits of the integer.