PHP Multi-dimensional arrays
<p>I'm banging my head trying to get my mind around this.  I have worked with arrays before but I seem to be struggling with them in PHP.  Trust me I've looked at questions here and other places so I apologize upfront for how basic this question probably is.  What I'm trying to do is make an array of an array???</p>

<p>basically, I'm trying to make a session global variable so that it stores an array and that can be continually added to.</p>

<pre><code>$_SESSION['school'] = array('events' =&gt; array());
</code></pre>

<p>example of the events array would be:</p>

<pre><code>events['name'] = 'Homecoming';
events['date'] = 'December 15, 2012';
events['cost'] = 18.00;
events['attending'] = array();
events['attending'][$i] = 'John'
</code></pre>

<p>The use then would be something be</p>

<pre><code>echo $_SESSION['school'][$i][events]['name']; 
echo $_SESSION['school'][$i][events]['date']; 
echo $_SESSION['school'][$i][events]['cost'];
</code></pre>

<p>...</p>

<p>I've tried creating it as mentioned above and populating like this (again an array of events array)</p>

<pre><code>$_SESSION['school'] = array('events' =&gt; array());

$_SESSION['school'][$i][events]['name'] = 'Homecoming';
$_SESSION['school'][$i][events]['date'] = 'December 15, 2012';
$_SESSION['school'][$i][events]['cost'] = 18.00;
$_SESSION['school'][$i][events]['people'] = array('jane', 'john', 'bill');
</code></pre>

<p>This doesn't seem to work because I can tell the count is going up as it is being populated.  I've tried a few other ways but for some reason I haven't been able to figure it out.  Most examples I've come across don't appear to be similar to what I'm trying do.  Any help would be greatly appreciated.</p>

<p>--------UPDATED QUESTION BASED ON FEEDBACK--------
I think I'm very close to understanding you're updated logic and I tried updating my code but I'm running into the following issue.  I have an initialization php script which sets $_SESSION['school'] = array(array());.  This doesn't get populated until later and at one point I do a check on $_SESSION['school'] with count. It always returns 1 on the intial check even though nothing was added.  However, I assume its because it holds one empty array.  So it makes me question the structure. 
Since I'm a visual person this is what I think I need but I'm not sure how to construct it.</p>

<pre><code>//would be an 1 dimensional array that empty until a school is added later on in code.
$_SESSION['school'] = array();
</code></pre>

<p>it's elements would hold a multidimensional array with elements</p>

<pre><code>['name'] = 'Johnson High';
['address'] = '121 elm';
['city'] = 'san jose';
['state'] = 'California';
['events'] = array();
</code></pre>

<p>['events']  is empty until events are added but here are some items it would contain</p>

<pre><code>['events']['name'] = 'homecoming';
['events']['date'] = 'December 15, 2012';
['events']['cost'] = '18.00';
</code></pre>

<p>in the end the $_SESSION['school'] could hold 1 to many schools that I could loop through.</p>

<p>Now to my misunderstanding of danL updated logic, I don't see how name and events would have the same index?  When I look at the code I get a sense that the the $_SESSION['school'] would look like this </p>

<pre><code>$_SESSION['school']{ 'name' =&gt; 'Johnson High',
                     'events' =&gt; array('basketball', 'soccer', 'football'),
                     'name' =&gt; 'West Forsyth High',
                     'events' =&gt; array('basketball', 'soccer', 'football')};
</code></pre>

<p>If that's the case then each element is at a different index.  I must be missing something fundamental here.  I'm continually trying to read up and make the connection to what I'm doing wrong.  I think I'm just looking at the problem from the wrong angle.</p>
