2 dimensional array declaration and filling

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
mavera2
Forum Newbie
Posts: 8
Joined: Sat Sep 03, 2011 11:54 am

2 dimensional array declaration and filling

Post by mavera2 »

I declare and fill 1 dimensional arrays with:

$myarray = array();
$i=1;
$myarray[$i]='banana'
-----------

But i couldn't declare and fill multidimensional arrays.
In http://php.net/manual/tr/language.types.array.php multidimensional array filling is written.
But i couldn't find how to declare a 2 dimensional array and fill it in a foreach loop.

Thank you.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: 2 dimensional array declaration and filling

Post by Celauran »

Code: Select all

$myarray[$i][] = 'banana';
Post Reply