is_array


array apg

CHECK if a given VARIABLE is or is not an ARRAY.





This function returns a BOOLEAN value when it tests the following variable types:

STRING, NUMERIC, BOOLEAN, ARRAY, NULL, RESOURCE or OBJECT.


This functions returns TRUE wheather $var is an ARRAY or FALSE in not.


To visualize the result, in this tutorial, we use var_dump associated with an  if  loop structure as a conditional evaluation framework.



<?php


bool is_array 
mix $var );


where,

$var VARIABLE to test

?>

$var


The variable to test.



  1 EXERCISE   

<?php

/* - - - - - - - - - - - - - - - - - - - - - - -
   This is a simple example using 
   a function: isarray -> user-defined
   to display if the variable
   is ARRAY
   - - - - - - - - - - - - - - - - - - - - - - - */
   
$var06a $_SERVER['REMOTE_ADDR'];
   
$var06b $_SERVER['HTTP_USER_AGENT'];
 
$var06c $_SERVER['HTTP_ACCEPT_LANGUAGE'];
 
$var06d M_E;
 
$var06e 1.6e-19
 
$var06f = [ 'c' => 299792458'G' => 6.67428E-11 ]; 
  
$var06g NULL;

$var06if false;

$var06iF FALSE;

$var06jt true;

$var06jT TRUE;

 
function 
isarray($var)
{

if(
is_array($var))
{
    
var_dump($var);
    echo 
'<br>This variable is an ARRAY!<br><br>';
}    
else
{
    
var_dump($var);
    echo 
'<br>This variable is NOT an ARRAY!<br><br>';    
}    
}

isarray($var06a);

isarray($var06b);

isarray($var06c);

isarray($var06d);

isarray($var06e);

isarray($var06f);

isarray($var06g);

isarray($var06if);

isarray($var06jT);

?>

 RESULT   

string(3) "::1"
This variable is NOT an ARRAY!

string(78) "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0"
This variable is NOT an ARRAY!br>
string(35) "pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3"
This variable is NOT an ARRAY!

float(2.718281828459)
This variable is NOT an ARRAY!

float(1.6E-19)
This variable is NOT an ARRAY!


array(2) { ["c"]=> int(299792458) ["G"]=> float(6.67428E-11) }
This variable is an ARRAY!


NULL
This variable is NOT an ARRAY!

bool(false)
This variable is NOT an ARRAY!

bool(true)
This variable is NOT an ARRAY!