‘isset’ construct and multiple parameters


Posted in: php | Save to del.icio.us | Twit This! 30 Jan 2010

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);



Share this post

Share on Facebook
Share on Twitter
Share on StumbleUpon
Share on Delicious
Share on Digg
Share on Technorati
Share on Reddit
Feeds RSS Subscribe to site Feed

Other related posts



3 Responses

1

Nesakysiu

February 1st, 2010 at 8:32 am

Nice :-)

2

kiran aghor

February 4th, 2010 at 8:55 pm

wow great. thanks for sharing this.

3

Chris Roane

February 26th, 2010 at 2:36 pm

Good to know. I know that I’ve done the long hand version many times before and this will save a lot of time.

Comment Form

Use the html <code> tag to insert small source code snippets

For longer code examples use http://pastie.org/.

Get latest updates by E-mail

About this blog

This site is a digital habitat of Sameer, a freelance web developer working from Pune.More

Recent Comments

  • sameer: Check to see if the 'IDE > options > format' is set to HTML. [...]
  • sameer: Google strips any newline characters form the text. Although it does accept it with the online trans [...]
  • Arjan: Fiddler is a debugging tool for IE (not Microsoft's Fiddler) [...]
  • Susan Martin: while creating a test for site, command icons on IDE greyed out and do not respond when selected. I [...]
  • Saar: Thanks for this example. helped me a lot. I have 1 problem, I am translating chunks of code, but I [...]
  • sameer: You can add extra GET variables in the options array as below: $pager_options = array( 'mode [...]
  • Martin: How can you carry over your own variables into the URL? I am using a form to POST a couple of var [...]
  • nancy: thanks very much ! first tools [...]

  • Users Online

    • 12 Users Online
    • 10 Guests, 2 Bots