Open In App

PHP get_resources() Function

The get_resources() function is an inbuilt function in PHP that returns active resources in an array form, & optionally, the resource type will be filtered.

Syntax:



array get_resources(?string $type = null)

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

Return Value: This function returns current resources in an array form, indexed by resource number.



Example 1: In the below code, we will return specific resources using the get_resources() function.




<?php
var_dump(get_resources('stream')) ;
?>

Output:

array(3) {
    [1]=> resource(1) of type (stream)
    [2]=> resource(2) of type (stream)
    [3]=> resource(3) of type (stream)
}

Example 2: This is another example that demonstrates the get_resources() function.




<?php
$fp = tmpfile();
var_dump(get_resources());
?>

Output:

array(4) {
    [1]=> resource(1) of type (stream)
    [2]=> resource(2) of type (stream)
    [3]=> resource(3) of type (stream)
    [4]=> resource(4) of type (stream)
}

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

Article Tags :