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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:57:21+00:00 2026-05-26T01:57:21+00:00

I just don’t get it, it’s actually so basic, but I just can’t make

  • 0

I just don’t get it, it’s actually so basic, but I just can’t make it happen. I’ve got the following array:

Array ( 
[15] => Array ( 
        [id] => 15 
        [name] => Name of course 
        [date] => 1300863780 
        [price] => 0 ) 
[14] => Array ( 
        [id] => 14  
        [name] => Name of course 
        [date] => 1303545780 
        [price] => 0 ) 
)

And I just want to rearrange it a little bit, so it looks like:

Array ( 
[03] => Array ( 
        [id] => Array(15) 
        [name] => Array(Name of course)
        [day] => Array(23)
        [year] => Array(2011)
        [price] => Array(0) ) 
[04] => Array ( 
        [id] => Array(14) 
        [name] => Array(Name of course)
        [day] => Array(23)
        [year] => Array(2011)
        [price] => Array(0) ) 
)

To explain it: I want to make the month (calculated from [date]) to be the main key and then more or less list each field in their corresponding fields/some new ones. Later on there will be more entries in the same month, so it makes sense to arrange it that way.

What I got yet is the following, and for the sake of foo, I don’t understand why it doesn’t work that way (and no other way I can come up with). $this->data is the array above!

<?php
    foreach($this->data as $field)
    { 
        while(list($id, $name, $date, $price) = each($field))
        {
            $month = date('m',$date);
            $this->month[$month]['id'] = $id;
            $this->month[$month]['name'] = $name;
            $this->month[$month]['day'] = date('F',$date);
            $this->month[$month]['year'] = date('Y',$date);
            $this->month[$month]['price'] = $price;
        }
    }
?>

All I get are heaps of ‘undefined offset’ notices in the line with the list() statement.
Much appreciate your 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-26T01:57:22+00:00Added an answer on May 26, 2026 at 1:57 am

    To explain it: I want to make the month (calculated from [date]) to be
    the main key and then more or less list each field in their
    corresponding fields/some new ones. Later on there will be more
    entries in the same month, so it makes sense to arrange it that way.

    As I wrote in comment, after reading this, I would not store all those id, name etc as arrays. $this->month[$month][$n]['id'] is the way to go, not $this->month[$month]['id'][$n], i.e., you need multiple “arrays of id, name etc” rather than “separate array of id, another array of name etc“.

    function convert(array $data) {
        $result = array();
        foreach ( $data as $value ) {
            $month = date('m', $value['date']);
            $value['day' ] = date('d', $value['date']);
            $value['year'] = date('Y', $value['date']);
            unset($value['date']);
            $result[$month][] = $value;
        }
        return $result;
    }
    
    $data = array(
        15 => array(
            'id'    => '15',
            'name'  => 'Name of course',
            'date'  => '1300863780',
            'price' => '0',
        ),
        16 => array(
            'id'    => '16',
            'name'  => 'Name of course',
            'date'  => '1300863780',
            'price' => '0',
        ),
        14 => array(
            'id'    => '14',
            'name'  => 'Name of course',
            'date'  => '1303545780',
            'price' => '0',
        ),
    );
    
    print_r(convert($data));
    

    Output:

    Array
    (
        [03] => Array
            (
                [0] => Array
                    (
                        [id] => 15
                        [name] => Name of course
                        [price] => 0
                        [day] => 23
                        [year] => 2011
                    )
                [1] => Array
                    (
                        [id] => 16
                        [name] => Name of course
                        [price] => 0
                        [day] => 23
                        [year] => 2011
                    )
            )
        [04] => Array
            (
                [0] => Array
                    (
                        [id] => 14
                        [name] => Name of course
                        [price] => 0
                        [day] => 23
                        [year] => 2011
                    )
            )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to retrive a dataset to a Gridview, but I just don't get
Sry but I just don't understand what is wrong in my syntext, can you
I just don't get it where is the problem but here's the error: Fatal
I just don't get the various elements of the traceview output, and I can't
OK, I've tried but I just don't get it. I have two classes logger
Maybe I'm slow, but I just don't get why you would ever use an
this is a silly n00b question but i just don't get it to work.
This is a easy question,but I just don't get it. I want to detect
Can someone explain the logic behind this for loop... I just don't get it
I just wanted to take a look at Mongo-DB. But i just don't get

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.