• PHP Video Tutorials

PHP - get_resource_id() Function


Advertisements

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

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements