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 6471039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:10:46+00:00 2026-05-25T06:10:46+00:00

I want to create something like the following array [Schedule_Date_Group] => Array ( [Schedule_Date]

  • 0

I want to create something like the following array

[Schedule_Date_Group] => Array
            (
                [Schedule_Date] => Array
                    (
                        [Friday, September 16, 2011] => Array
                            (
                                [Schedule_Item] => Array
                                    (
                                        [nid] => 763
                                        [time] => 1:15 PM
                                        [title] => What a Publisher Does: 5 Reasons Why You Need a...
                                        [event_type] => events
                                        [length] => 
                                        [movie_type] => 
                                        [details] => 
                                    )

                                [Schedule_Item] => Array
                                    (
                                        [nid] => 763
                                        [time] => 1:15 PM
                                        [title] => What a Publisher Does: 5 Reasons Why You Need a...
                                        [event_type] => events
                                        [length] => 
                                        [movie_type] => 
                                        [details] => 
                                    )

                            )

                    )

            )

But I have a few issues, first the array seems to be getting created with a preceding # for the first value. Example

[7] => Array
    (
        [Schedule_Date_Group] => Array
            (

And my arrays are not pushing it under the Date Array ([Friday, September 16, 2011] => Array) They are just being added to the end as a normal array. Example

[7] => Array
    (
        [Schedule_Date_Group] => Array
            (
                [Schedule_Date] => Array
                    (
                        [Friday, September 16, 2011] => Array
                            (
                                [Schedule_Item] => Array
                                    (
                                        [nid] => 763
                                        [time] => 1:15 PM
                                        [title] => What a Publisher Does: 5 Reasons Why You Need a...
                                        [event_type] => events
                                        [length] => 
                                        [movie_type] => 
                                        [details] => 
                                    )

                            )

                    )

            )

    )

[8] => Array
    (
        [Schedule_Item] => Array
            (
                [nid] => 764
                [time] => 1:30 PM
                [title] => Navigating the Road to Licensing Music For Your...
                [event_type] => events
                [length] => 
                [movie_type] => 
                [details] => 
            )

    )

How can I fix these two issues. They are again, #’s preceding the Schedule_Date_Group array and the sub arrays being added to the end rather then nested under the date group array.

PHP For the main schedule item and date group part

$xml[] = array("Schedule_Date_Group" => array("Schedule_Date" => array($pretty_date => array("Schedule_Item" => array("nid" => $do['nid'], "time" => $pretty_time, "title" => $title, "event_type" => $do['field_event_type_value'], "length" => $do['field_length_value'], "movie_type" => $do['field_movie_type_value'], "details" => $schedule_details)))));

PHP for the sub menu items

$xml[] = array("Schedule_Item" => array("nid" => $do['nid'], "time" => $pretty_time, "title" => $title, "event_type" => $do['field_event_type_value'], "length" => $do['field_length_value'], "movie_type" => $do['field_movie_type_value'], "details" => $schedule_details));

It is being looped through so there is no way for me to just create a giant array. And if a new “Schedule Date” is set it will create a new [Schedule_Date_Group] => Array
(
[Schedule_Date] => Array
(
[Friday, September 16, 2011] => Array
(

and all the sub content should go under that new one.
So I would end up with

DATE
 - Schedule_Item 1
 - Schedule_Item 2
 - Schedule_Item 3
 - Schedule_Item 4
New Date
 - Schedule Item 5
 - Schedule Item 6

etc…

Any help?

  • 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-05-25T06:10:46+00:00Added an answer on May 25, 2026 at 6:10 am

    Firstly, using a huge array to manually generate some XML like this is not the way to do it. Use something like XMLWriter or DOM instead, then you can build your document on the fly as you obtain your data. However, if you really want to, or are forced to do it like this, read on…


    Secondly, what you are trying to do cannot be done. This is because you want use the same array key for multiple entries which won’t work – you will just end up overwriting your previous entry.

    Thirdly, your numeric keys are appearing because you are using $xml[] (array_push() behaves in the same way) and it will always add a numeric key because you have not told it what you want your text key to be.

    Fourthly, your extra items are being added to the outer level of the array because that is what you have told PHP to do. $xml[] will always add a new key to the outer level of the $xml variable because you have not told PHP you are dealing with an inner array.

    Your structure needs to be more like this:

    $scheduleDateGroup = array (
      'Friday, September 16, 2011' => array (
        // These are your schedule items...
        0 => array( ... ),
        1 => array( ... ),
        2 => array( ... ),
        ...
      ),
      'Saturday, September 17, 2011' => array (
        0 => array( ... ),
        1 => array( ... ),
        2 => array( ... ),
        ...
      ),
      ...
    );
    

    …and you can push new items onto specific days like this:

    $scheduleDateGroup[$date][] = array( ... );
    

    Then you can loop through it and turn it into XML with something like this:

    echo "<Schedule_Date_Group>\n";
    foreach ($scheduleDateGroup as $day => $schedules) {
      echo "  <Schedule_Date date=\"$day\">\n";
      foreach ($schedules as $item) {
        echo "    <Schedule_Item";
        foreach ($item as $attr => $value) echo " $attr=\"$value\"";
        echo " />\n";
      }
      echo "  </Schedule_Date>\n";
    }
    echo "</Schedule_Date_Group>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create something like a leaflet/magazine using Latex. Is it possible to
Is there a open source meme tracker ? I want to create something like
I want to create a unique id but uniqid() is giving something like '492607b0ee414'
In C# if I want to create a Custom Event you do something like
I want to create a number of masked edit extenders from codebehind. Something like:
I want to do something like this: create table app_users ( app_user_id smallint(6) not
I want to do something like this create type Item as object ( id
I want to do something like: MyObject myObj = GetMyObj(); // Create and fill
When I create something like the following: <mx:DataGrid idmyDataGrid itemEditBegin=myDataGrid_itemEditBeginHandler(event) /> When does the
I want to create something like a recorder whichs tracks all actions of a

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.