Jump to content

[SOLVED] working with arrays - storing lots of information?


Recommended Posts

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?

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'?

 

 

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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