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:
- type: This parameter will restrict the function to return only the resources for the given type if defined. If the string is unknown, it will return unknown resources. It will return all resources if this is omitted.
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
<?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
<?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