• PHP Video Tutorials

PHP - is_countable() Function



Definition and Usage

The function is_countable() is used to check whether the contents of the variable is a countable value.

Syntax

bool is_countable ( mixed $value )

Parameters

Sr.No Parameter & Description
1

value

The value which needs to be checked

Return Values

This function returns boolean value true if the value is countable, else returns false.

Dependencies

PHP 7.3 and above

Example

Following example demonstrates return values with different types of variables −

<?php
   var_dump(is_countable([1, 2, 3])); // bool(true)
   var_dump(is_countable(new ArrayIterator(['a', 'b', 'c']))); // bool(true)
   var_dump(is_countable(new ArrayIterator())); // bool(true)
   var_dump(is_countable(new stdClass())); // bool(false)
   var_dump(is_countable("tutorialspoint")); // bool(false)
?>

Output

This will produce following result −

bool(true)
bool(true)
bool(true)
bool(false)
bool(false)
php_variable_handling_functions.htm
Advertisements