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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:31:15+00:00 2026-06-08T23:31:15+00:00

A novice array question… Given an array with this structure: $post_dates Array [1] [0…0]

  • 0

A novice array question…

Given an array with this structure:

$post_dates Array [1]   
    [0...0] 
        2640    Array [2]   
            [0...1] 
                _id 2640    
                date_posted MongoDate

How would I access the date_posted element when the 1st level key is not always the same?
I thought I could just have this:

$post_dates[0]['date_posted']

But that’s giving me an ‘Undefined Offset’ message.
I’ve also tried

$post_dates[0][1]

but that gives the same message.

This is the code block where I am getting the error:

foreach($posts as $post){

        $post_dates = iterator_to_array($posts_coll->find(array("topic_id"=>$post['_id']), array("date_posted"=>true)));

        if (empty($post_dates)){ // No replies, therefore last post date = date_posted
            //$replies = 0;
            $lastPost = date("d-M-Y h:i:s", $post['date_posted']->sec);
            echo "condition 1, last post date: " . $lastPost . "<br>";
        }
        elseif (count($post_dates) == 1) { // One reply, therefore last post date = $post_dates[date_posted]            
            //$lastPost = date("d-M-Y h:i:s", $post_dates[0][1]->sec);
            echo "condition 2, last post date: " . $lastPost . "<br>";
            var_dump($post_dates[0]['_id']);
        }
        else {
            // code to determine max date_posted if there is more than one reply
        }

}
  • 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-08T23:31:17+00:00Added an answer on June 8, 2026 at 11:31 pm

    If you don’t know any of the keys in the chain $array["known"]["also_known"][???]["date_posted"], you’ll have to iterate the array in order to figure out which has the date_posted you need.

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

Sidebar

Related Questions

I'm a novice Javascript programmer, so I apologize if this question makes no sense.
this might be a bit of a novice question and here is my situation:
I'm sorry if this is a novice question, but I'm not very knowledgeable when
This question is about removing sequences from an array, not duplicates in the strict
A question from a complete Python novice. I have a column array where I
This may be a lame question but I am a total novice with regular
Quick novice question: I want to extend a class as an array, like so
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
I am a novice to spring dm so pardon my simple question. I downloaded
I'm a novice in XSLT and I'm struggling a lot with this issue: I

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.