Multi Dimensional Array in Form from check boxes

Hi,

I have a form setup to use check boxes.
On this form I have an array text input for a persons name
<input name=\"contact_name[]\" type=\"text\">
The I have a list of some checkboxes dynamically created from the db, say five options:
<input type=\"checkbox\" name=\"favourite_food[]\" value=\"$result[food_id]\">$result[food_name]

I want to then print the persons name, and then the food s/he likes, according to what was ticked

At the moment It is printing the persons name, then all foods that were ticked, not just the foods that are relative to each specific person.

Basically, I dont know how I need to index the above arrays so that they foods belong to one person, and how would i do the foreach for this ?
LVL 1
DelacourtAsked:
Who is Participating?
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.

snoyes_jwCommented:
Looks like you need to name your fields like this:
contact_name[]
favourite_food[0][]
favourite_food[0][]
favourite_food[0][]
...
contact_name[]
favourite_food[1][]
favourite_food[1][]
favourite_food[1][]

Then you can loop through the results like this:
foreach ($contact_name as $key=>$name) {
  echo $name;
  foreach ($favourite_food[$key] as $food) {
    echo $food;
  }
}
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
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.