Type identifier functions

A number of functions are available for determining a variable's type, including is_array(), is_bool(), is_float(), is_integer(), is_null(), is_numeric(), is_object(), is_resource(), is_scalar(), and is_string().

Because all of these functions follow the same naming convention, arguments, and return values, their introduction is consolidated into a single example. The generalized prototype follows:


boolean is_name(mixed var)

All of these functions are grouped in this section because each ultimately accomplishes the same task. Each determines whether a variable, specified by var, satisfies a particular condition specified by the function name.

If var is indeed of the type tested by the function name, TRUE is returned; otherwise, FALSE is returned. An example follows:

<?php
$item = 43;
printf("The variable \$item is of type array: %d <br />", is_array($item));
printf("The variable \$item is of type integer: %d <br />",
is_integer($item));
printf("The variable \$item is numeric: %d <br />", is_numeric($item));
?>

This code returns the following:

The variable $item is of type array: 0
The variable $item is of type integer: 1
The variable $item is numeric: 1

You might be wondering about the backslash preceding $item. Given the dollar sign's special purpose of identifying a variable, there must be a way to tell the interpreter to treat it as a normal character should you want to output it to the screen. Delimiting the dollar sign with a backslash will accomplish this.





Content