In php there are many function provided which are used to provide the facility of input type validity checker.Here is table which illustrate a small description :-
Type identifier function | Description |
is_array() | Check for array type |
is_bool() | Check for true or false type |
is_float() | Check for floating point number type |
is_integer() | Check for integer type |
is_null() | Check for null value |
is_numeric() | Check for numeric value |
is_object() | Check for object type |
is_resource() | Check for resource type |
is_scalar() | Check for scalar data type |
is_string() | Check for string or not |
Example:-
- <?php
- $itemno = 435;
- printf(" \$itemno is of type array: %d <br />", is_array($itemno));
- printf(" \$itemno is of type integer: %d <br />", is_integer($itemno));
- printf("\$itemno is numeric: %d <br />", is_numeric($itemno));
- printf("\$itemno is object: %d <br />", is_object($itemno));
- printf("\$itemno is resource: %d <br />", is_resource($itemno));
- printf("\$itemno is scalar: %d <br />", is_scalar($itemno));
- printf("\$itemno is string: %d <br />", is_string("hello"));
- printf("\$itemno is bool: %d <br />", is_bool(true));?>
The output is:
$itemno is of type array: 0
$itemno is of type integer: 1
$itemno is numeric: 1
$itemno is object: 0
$itemno is resource: 0
$itemno is scalar: 1
$itemno is string: 1
$itemno is bool: 1
Here 1 represent ‘true’ and 0 represent ‘false’.