Friday, 3 October 2014

gettype in PHP

gettype — Get the type of a variable
Syntax:string gettype ( mixed $var )
Returns the type of the PHP variable var. 
        For type checking, use is_* functions.
Parameter:var
    The variable being type checked.
Return Values:
Possible values for the returned string are:
        "boolean"
        "integer"
        "double" (for historical reasons "double" is returned in case of a float, and not simply "float")
        "string"
        "array"
        "object"
        "resource"
        "NULL"
        "unknown type"

Example #1
<?php
$data = array(1, 1., NULL, new stdClass, 'foo');
foreach ($data as $value) {
    echo gettype($value), "\n";
}
?>
O/P:
integer
double
NULL
object
string

0 comments:

Post a Comment