bigjoe11a Posted October 3, 2011 Share Posted October 3, 2011 on my web site that I been redoing, I been trying to come up with some ideas on how to set up arrays related to that user. The one that's logged in. and I been doing some reading on Multidimensional Arrays. well it has me completely lost. Multidimensional Arrays are new to me. and after coding in php for the last 4 1/2 years. I think it's about time i learn this. my idea is to setup some thing like this if($user['name']['is_admin']) {//trueelse//false} this means that the 'user' is 'is_admin' or it's false. so when a user logs in, and after it reads the database rows and returns the users name and other user info. how would I set the values to the Multidimensional Array... Please help with some code. Link to comment Share on other sites More sharing options...
Ingolme Posted October 3, 2011 Share Posted October 3, 2011 The first question you need to ask yourself is do you need a multidimensional array? From what it looks like, you only need a monodimensional array. if($user['is_admin']) { // Do something} A multidimensional array is just an array where each element of the array is another array. $a = array();$a[0] = array();$a[1] = array();$a[2] = array(); Link to comment Share on other sites More sharing options...
bigjoe11a Posted October 3, 2011 Author Share Posted October 3, 2011 See that's what I don't under stand. Just what I will need. What I need is an array related to each user. so after the user logs in. How would I go a bout setting it so that I can call it like that. A Small Sample : $name = $_SESSION['usename'];$email = $_SESSION['email'];$admin = $_SESSION['is_admin']; using the samples above. How would I add them to an array() so that I can use them threw out my pages. Or web site. Link to comment Share on other sites More sharing options...
Ingolme Posted October 3, 2011 Share Posted October 3, 2011 This would work: $user = array( 'name' => $_SESSION['username'], 'email' => $_SESSION['email'], 'admin' => $_SESSION['is_admin']); Link to comment Share on other sites More sharing options...
bigjoe11a Posted October 3, 2011 Author Share Posted October 3, 2011 ok, so then I would use that in what way if($user['name']['admin']) {//this means the use is an admin} else {//this means the user is NOT an admin} I'm I right Link to comment Share on other sites More sharing options...
thescientist Posted October 3, 2011 Share Posted October 3, 2011 no. Perhaps it would be helpful to review array's in the w3schools tutorials. Ingolme already give you the example of how to use it, and how to implement it. Make it $user = array( 'name' => $_SESSION['username'], 'email' => $_SESSION['email'], 'admin' => $_SESSION['is_admin']); use it if($user['admin']) { // Do something} edit: changed from is_admin to admin in "use it" example. Link to comment Share on other sites More sharing options...
bigjoe11a Posted October 3, 2011 Author Share Posted October 3, 2011 Cool, thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.