• PHP Video Tutorials

PHP - get_resource_id() Function



Definition and Usage

The function get_resource_id() returns an integer identifier for the given resource. The resource is a type of variable that holds a reference to an external resource. The resource can be a filehandle, a database connection, or a URL handle. Every resource is identified by a unique id. In the previous versions of PHP, we needed to cast a resource to int to get the resource id.

Syntax

int get_resource_id ( resource $res )

Parameters

Sr.No Parameter & Description
1

res

A type of variable that holds a reference to an external resource.

Return Values

This function returns int identifier for the given res. This function is essentially an int cast of res to make it easier to retrieve the resource ID.

Dependencies

PHP 8.0

Example

Following example demonstrates the use of function get_resource_id() −

<?php
   $x = fopen('test.txt', 'rb');
   echo get_resource_id($x);
?>

Output

This will produce following result −

1
php_variable_handling_functions.htm
Advertisements