Make a function handle arrays

I want the following function to be able to accept arrays, or a single value.

I am implementing this into an existing enterprise application, so it needs to be bulletproof, if you know what I mean.

I would ideally like it to handle:

a. a single value
b. an array
c. null ( do nothing )

Thanks!
// unset a value
function ss_clear_info($key)
{
	unset($_SESSION[$key]);
}

Open in new window

LVL 1
edvinsonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

artmsCommented:
How it supposed to handle array? With each array element it should unset that value from $_SESSION global array?
0
edvinsonAuthor Commented:
I would like the function to be able handle both of these scenerios ( for backward compatibility ):

ss_clear_info($aSingleKey)

ss_clear_info($one, $two, $third, $etc, $etc)

and finally

ss_clear_info($myArrayOfKeysToClear)

0
edvinsonAuthor Commented:
I think I came up with my own solution...
function ss_clear() {
 
	$numargs = func_num_args();
	
	if($numargs>0) {
 
		$arg_list = func_get_args();
 
		for ($i = 0; $i < $numargs; $i++) {
       		if(gettype($arg_list[$i] == 'array')){
				foreach ($arr as $key => $value) {
    				unset($_SESSION[$key]);
				}
		    } else {
				unset($_SESSION[$key]);
			}
   		}
		
		return true;
		
	} else {
		
		return false;
		
	}
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

artmsCommented:
To bullet proof solution you should also check if array in array is not passed or this type can be simply ignored...
0
edvinsonAuthor Commented:
Ok, cool. since i have to give the points to someone, could you show me , so i can award you the points?
0
artmsCommented:
You can close the ticket by not giving anyone points (well nobody helped, you helped yourself :) ). Check options or ask moderators for help how to close it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.