‘isset’ construct and multiple parameters

PHP programmers are frequently into using the various is_x group of functions: is_int, is_null etc. All of this functions take a single parameter which leads you to believe that other similar constructs take only a single parameter. Like the isset and unset constructs, which by the way take multiple parameters as shown below, which might help you save some keystrokes.

So instead of writing:

$var1 = 'a';
$var2 = 'b';
$var3 = 'c';
$var4 = 'd';
 
if(isset($var1) && isset($var2) && isset($var3) && isset($var4))
{
    // All variables are set, do something
}

We can write:

$var1 = 'a';
$var2 = 'b';
$var3 = 'c';
$var4 = 'd';
 
if(isset($var1, $var2, $var3, $var4))
{
    // Will return TRUE only if all of the parameters are set
}

Same with the unset() construct:

unset($var1, $var2, $var3, $var4);
php

4 thoughts on “‘isset’ construct and multiple parameters

  1. Oh, very nice, i relly never see this function, thank you for that post! keep the good job.

    So, 1 question, isset($var, $var1) is faster than isset($var) && isset($var1).

    Thank you again.

Comments are closed.