Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9091735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:41:00+00:00 2026-06-16T22:41:00+00:00

I’m banging my head trying to get my mind around this. I have worked

  • 0

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

basically, I’m trying to make a session global variable so that it stores an array and that can be continually added to.

$_SESSION['school'] = array('events' => array());

example of the events array would be:

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

The use then would be something be

echo $_SESSION['school'][$i][events]['name']; 
echo $_SESSION['school'][$i][events]['date']; 
echo $_SESSION['school'][$i][events]['cost'];

…

I’ve tried creating it as mentioned above and populating like this (again an array of events array)

$_SESSION['school'] = array('events' => 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');

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.

——–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.

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

it’s elements would hold a multidimensional array with elements

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

[‘events’] is empty until events are added but here are some items it would contain

['events']['name'] = 'homecoming';
['events']['date'] = 'December 15, 2012';
['events']['cost'] = '18.00';

in the end the $_SESSION[‘school’] could hold 1 to many schools that I could loop through.

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

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

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:41:01+00:00Added an answer on June 16, 2026 at 10:41 pm

    Ok, so based on the help of danL (thanks so much). I’ve figured out what I need to do. So in my initialization script I set,

    $_SESSION['school'] = array();
    

    after further processing I create a events array to store the info in.

    $event = arra();
    $event['name'] = 'Homecoming';
    $event['date'] = 'December 15, 2012';
    $event['cost'] = '18.00';
    $event['people'] = array();
    $event['people'] = { 'john', 'mary', 'mark', 'janice'};
    

    the last two lines could probably be joined into one line.

    then I add the event array to the school array as,

    $_SESSION['school'][] = $event;
    

    I don’t know how I get spun around so easily with associative arrays but thanks for all the help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.