Thursday, October 23, 2025
HomeLanguagesPHP get_resources() Function

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:

  • 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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
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