PHP is resource

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : is_resource() function

Description

The is_resource () function is used to find whether a variable is a resource or not.

Version

(PHP 4 and above)

Syntax

is_resource(var_name)

Parameter

Name

Description

Required /
Optional

Type

var_name

The variable being checked

Required

Mixed*

*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Return value

TRUE if var is a resource, FALSE otherwise.

Value Type : Boolean.

Example :

  1. $fh = fopen('demo.txt','r');  

  2. if (is_resource($fh))   

  3. {  

  4. echo "File is open successfully......";  

  5. }  

  6. else  

  7. echo "wrong way to open a file";  

  8. ?>  

Output :

File is open successfully......