is_resource


clipping apg

CHECKS if a given VARIABLE is or is not a RESOURCE.





This function returns:

TRUE if $value is a RESOURCE
or
FALSE if $value is not a RESOURCE.



<?php


bool is_resource 
mix $value );

where,

$value Variable to test

?>

 $value 


The variable to test.



 RESOURCE 


A RESOURCE is a special variable, holding a reference to an external RESOURCE.

Resources are created and used by special functions.

To find out which PHP functions use or destroy a resource, click on the following link:

List of Resource Types 

This function is_resource can be used to determine if a variable is a resource.



  1 EXERCISE   

<?php 

$f1 
=  'test'

$opts1 = [ 'http' => [ 'method'=>"POST"
                 
'header' => "Accept-language: en"
                 
'content' => $f1 ] ];
                 
$test1 is_resource($opts1);

if (
$test1 == true)
{
    
var_dump($opts1) . '<br><br>';
    echo 
"IS a RESOURCE<br><br>";
}
else
{
    
var_dump($opts1) . '<br><br>';
    echo 
"<br><br>IS NOT a RESOURCE<br><br>";    
}

?> 

 RESULT   

array(1) { ["http"]=> array(3) { ["method"]=> string(4) "POST" ["header"]=> string(19) "Accept-language: en" ["content"]=> string(4) "test" } }

IS NOT a RESOURCE


  2 EXERCISE   

<?php

$var02c 
$_SERVER['HTTP_ACCEPT_LANGUAGE'];
 
$var02d M_E;
 
$var02e 1.6e-19
 
$var02f = [ 'c' => 299792458'G' => 6.67428E-11 ]; 
  
$var02g NULL;

$var02h imagecreate100100 );

function 
ISresource($var)
{

if(
is_resource($var))
    {
    
var_dump($var);
    echo 
'<br>is a RESOURCE<br><br>';
    @
fclose($var);
    }
    else
    {
    
var_dump($var);
    echo 
'<br>is NOT a RESOURCE<br><br>';
    }
}
    
ISresource($var02c);

ISresource($var02d);
 
ISresource($var02g);

ISresource($var02h);

?>

 RESULT   

NULL
is NOT a RESOURCE

float(2.718281828459045090795598298427648842334747314453125)
is NOT a RESOURCE

NULL
is NOT a RESOURCE

object(GdImage)#1 (0) { }
is NOT a RESOURCE