Jump to content

[SOLVED] Loop through array and create variable session variable names


mwstewart

Recommended Posts

Hello guys & girls,

                      As part of my user authentication class I've written a method that sets session variables. I pass an array to the function by reference which contains elements populated with information from the users table in the DB (name, street, country etc)

 

At the moment the function looks like this:

 

/* Set the session variables for easy access to user data */
function _setSessionData(&$userData) { 
$_SESSION['loggedOn'] = true; // Logged on

		$_SESSION['userID'] = $userData['UserID'];
		$_SESSION['username'] = $userData['UserName'];
		$_SESSION['password'] = $userData['Password'];
		$_SESSION['firstName'] = $userData['FirstName'];
		$_SESSION['surname'] = $userData['Surname'];
		$_SESSION['email'] = $userData['Email'];
		$_SESSION['street'] = $userData['Street'];
		$_SESSION['city'] = $userData['City'];

		return true;
	}

 

What I'm wondering is if it is possible to loop through the $userData array, and dynamically name and populate the session variables rather than listing them all and assigning like I have?

 

Cheers,

Mark

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.