Type Identifiers Functions in PHP

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:-

  1. <?php  
  2. $itemno = 435;  
  3. printf(" \$itemno is of type array: %d <br />"is_array($itemno));  
  4. printf(" \$itemno is of type integer: %d <br />"is_integer($itemno));  
  5. printf("\$itemno is numeric: %d <br />"is_numeric($itemno));  
  6. printf("\$itemno is object: %d <br />"is_object($itemno));  
  7. printf("\$itemno is resource: %d <br />"is_resource($itemno));  
  8. printf("\$itemno is scalar: %d <br />"is_scalar($itemno));  
  9. printf("\$itemno is string: %d <br />"is_string("hello"));  
  10. 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’.