• PHP Video Tutorials

PHP - is_array() Function


Advertisements

Definition and Usage

The function is_array() is used to check whether a variable is an array or not.

Syntax

bool is_array ( mixed $value )

Parameters

Sr.No Parameter & Description
1

value

The variable being evaluated

Return Values

This function returns boolean value true if value is an array, otherwise returns false.

Dependencies

PHP 4 and above

Example

Following example demonstrates use of is_array() function −

<?php
   $a = array('a', 'b', 'c');
   echo 'a '.(is_array($a) ? 'Is an Array'   : 'not an Array').'<br>';

   $b = array("a"=>"1", "b"=>"2", "c"=>"3");
   echo 'b '.(is_array($b) ? 'Is an Array'   : 'not an Array').'<br>';

   $c = 'this is a string';
   echo 'c is '.(is_array($c) ? 'Is an Array'   : 'not an Array').'<br>';
?>

Output

This will produce following result −

a Is an Array
b Is an Array
c is not an Array
php_variable_handling_functions.htm
Advertisements