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
https://forums.phpfreaks.com/topic/172319-solved-foreach-usage/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.