Open In App

PHP get_resource_id() Function

Last Updated : 22 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads