get_resource_id
Description
The get_resource_id of Variable Handling for PHP returns an integer identifier for the given resource.
Syntax
get_resource_id( resource $resource ): int
Parameters
resource
The evaluated resource handle.
Return
The int identifier for the given resource.
This function is essentially an int cast of resource to make it easier to retrieve the resource ID.
Examples
1 · resource
<? $filename = $_SERVER["DOCUMENT_ROOT"] . "/assets/txt/1.txt"; $mode = "r"; $resource = fopen($filename, $mode); $return = get_resource_id($resource); echo $return; fclose($resource); ?>
3
2 · cast
<? $filename = $_SERVER["DOCUMENT_ROOT"] . "/assets/txt/1.txt"; $mode = "r"; $resource = fopen($filename, $mode); echo (int)$resource; fclose($resource); ?>
3
Links
Related
Variable Handling
- boolval
- debug_zval_dump
- doubleval
- empty
- floatval
- get_debug_type
- get_defined_vars
- get_resource_type
- gettype
- intval
- is_array
- is_bool
- is_callable
- is_countable
- is_double
- is_float
- is_int
- is_integer
- is_iterable
- is_long
- is_null
- is_numeric
- is_object
- is_real
- is_resource
- is_scalar
- is_string
- isset
- print_r
- serialize
- settype
- strval
- unserialize
- unset
- var_dump
- var_export