Friday, October 17, 2025
HomeLanguagesPHP get_resource_id() Function

PHP get_resource_id() Function

The get_resource_id() function is an inbuilt function in PHP that returns the integer id given resource. This function provides a safe way of generating integers for a resource.

Syntax:

get_resource_id($resource) ;

Parameters: This function accepts one parameter that are described below:

  • $resource:  Name of the resource for which we want resource id.

Return Value: This function returns the int identifier of the given resource.

Example 1: In the below code example, we will print the id of the given resource.

PHP




<?php
  
$res = tmpfile() ;
  
// Print resource id of tmpfile
echo get_resource_id($res);
?>


Output:

4

Example 2: In the below code example, we are opening a text file and then returning his resource id. It may be resource id will be different according to your computer.

PHP




<?php
$res = fopen("text.txt", "rb");
echo get_resource_id($res);
?>


Output:

5

Reference: https://www.php.net/manual/en/function.get-resource-id.php

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS