multidimensional arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
xxroniss
Forum Newbie
Posts: 3
Joined: Tue Dec 15, 2009 5:37 pm
Location: Athens,Greece

multidimensional arrays

Post by xxroniss »

Hello

How can i construct an array like

Code: Select all

$array[$array1][$array2][$array3]=>value
with foreach statements?


thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: multidimensional arrays

Post by Christopher »

Code: Select all

foreach ($foo as $array1) {
     foreach ($bar as $array2) {
          foreach ($baz as $array3) {
               $array[$array1][$array2][$array3] = 'value';
          }
     }
}
(#10850)
User avatar
xxroniss
Forum Newbie
Posts: 3
Joined: Tue Dec 15, 2009 5:37 pm
Location: Athens,Greece

Re: multidimensional arrays

Post by xxroniss »

thanks for your answer

Please check this post in the code section and give me some guidelines
cause i suppose i dont really understand the array keys concept

viewtopic.php?f=1&t=110279

thnx again
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: multidimensional arrays

Post by pickle »

If you don't understand how arrays work - spend some time with Google looking for tutorials.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: multidimensional arrays

Post by aravona »

http://www.w3schools.com/php/php_arrays.asp

That site helped me with university work on arrays within php - it may clarify the basics for you (theres a complete reference guide for array functions right at the end too)
Post Reply