gettype

(PHP 4, PHP 5)

gettypeGet the type of a variable

Beskrivelse

string gettype ( mixed $var )

Returns the type of the PHP variable var. For type checking, use is_* functions.

Parametre

var

The variable being type checked.

Returnerings Værdier

Possibles values for the returned string are:

Eksempler

Eksempel #1 gettype() example

<?php

$data 
= array(11.NULL, new stdClass'foo');

foreach (
$data as $value) {
    echo 
gettype($value), "\n";
}

?>

The above example will output something similar to:

integer
double
NULL
object
string

Se også

add a note add a note

User Contributed Notes 1 note

up
-15
matt at appstate
19 years ago
Here is something that had me stumped with regards to gettype and is_object.
Gettype will report an incomplete object as such, whereas is_object will return FALSE.

<?php
if (!is_object($incomplete_obj)) {
   echo
'This variable is not an object, it is a/an ' . gettype($incomplete_obj);
}
?>

Will print:
This variable is not an object, it is a/an object
To Top