Jump to content

[SOLVED] foreach() usage


Bizty

Recommended Posts

I've never really gotten the hang of the foreach() function (compared to while), but it seems that foreach() is used alot when you need to go through an array of sorts.

 

I've now realised thats really to bad, and seeing I want to use the loop in a function I'd better get it right ^^

 

I have a function called CheckEmpty(), what it does is basicly checking if the supplied variable is empty. The issue is I have plenty variables (in the area of 100 for this particular script) that needs this check, so I wanted to do a simple check rather than:

 

function CheckEmpty($var1, $var2, $var3 ..... $var99)

{

}

 

so I was hoping I could do it dynamicly (maybe with an array?) where I simply go through all supplied vars.

 

I guess it would look something like:

function CheckEmpty()
{
foreach(something I dont get) 
{
     if(empty($var))
     {
          return true;
     }
     else
     {
         return false;
     }
}
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.