citricsquid Posted September 17, 2009 Share Posted September 17, 2009 Hi, I work lots with mysql and stuff and I've never actually learned about arrays indepth and now I need to know and I'm totally lost. I'm not sure if it's possible but it's worth asking. I have form data that I want to manipulate, normally I'd just chuck it in a database and play with that but this doesn't require it and I'd rather not use a database unless I have to. The following is entirely hypothetical, I just want to learn. There is a form, in it the user would enter: Name, price, hair colour and favourite food. They would then click submit and be taken to the processing page, now on this page I want to manipulate their entered data, I could always just do $name = ... etc, but I'd rather use an array because they could be entering 100 people. How do I store multiple values in an array? So I want to store the name, price, hair colour and favourite food in a single array. Is this possible and how would I go about it? Quote Link to comment https://forums.phpfreaks.com/topic/174567-solved-working-with-arrays-storing-lots-of-information/ Share on other sites More sharing options...
Adam Posted September 17, 2009 Share Posted September 17, 2009 Well yeah, easily possible. Have you actually read up on arrays at all? http://uk2.php.net/manual/en/function.array.php Quote Link to comment https://forums.phpfreaks.com/topic/174567-solved-working-with-arrays-storing-lots-of-information/#findComment-920008 Share on other sites More sharing options...
Garethp Posted September 17, 2009 Share Posted September 17, 2009 $Array['Name'] = 'Name'; $Array['Price'] = 'Price'; $Array['HairColor'] = 'Hair Color'; $Array['FavoriteFood'] = 'Favorite Food'; Get it? Quote Link to comment https://forums.phpfreaks.com/topic/174567-solved-working-with-arrays-storing-lots-of-information/#findComment-920011 Share on other sites More sharing options...
citricsquid Posted September 17, 2009 Author Share Posted September 17, 2009 oh I understand all this, but what I want to do is have multiple values for a single array value. Sorry if I explained it wrong, I'm really bad with explaining. I want to have $person['bob'] contain ALL the above values and be able to call them easily, but I just realised this probably isn't the correct way? Should I be setting up a new variable for each person? So $person1['name'] = 'bob', $person2['name'] = 'john'? Quote Link to comment https://forums.phpfreaks.com/topic/174567-solved-working-with-arrays-storing-lots-of-information/#findComment-920044 Share on other sites More sharing options...
Garethp Posted September 17, 2009 Share Posted September 17, 2009 No $Person['bob'][['Name'] = "Name"; $Person['bob'][Price'] = "Price"; See what I'm doing? It's called a Two Dimensional Array Quote Link to comment https://forums.phpfreaks.com/topic/174567-solved-working-with-arrays-storing-lots-of-information/#findComment-920046 Share on other sites More sharing options...
Adam Posted September 17, 2009 Share Posted September 17, 2009 How exactly are they entering the data? You say they could enter up to 100 people, what would your form look like? Quote Link to comment https://forums.phpfreaks.com/topic/174567-solved-working-with-arrays-storing-lots-of-information/#findComment-920051 Share on other sites More sharing options...
citricsquid Posted September 17, 2009 Author Share Posted September 17, 2009 No $Person['bob'][['Name'] = "Name"; $Person['bob'][Price'] = "Price"; See what I'm doing? It's called a Two Dimensional Array Brilliant, thankyou! I'll try that out now, this seems to be what I need. edit: I have no idea how I looked over this, I spent 3 hours trying to work it out and this is the obvious solution, cheers! Quote Link to comment https://forums.phpfreaks.com/topic/174567-solved-working-with-arrays-storing-lots-of-information/#findComment-920053 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.