Friday, November 14, 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
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7141 POSTS0 COMMENTS
Thapelo Manthata
6837 POSTS0 COMMENTS
Umr Jansen
6839 POSTS0 COMMENTS