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

  • Home
  • SEARCH
  • 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 799973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:13:03+00:00 2026-05-14T23:13:03+00:00

This is an array of objects showing a user uploading photos: Array ( [12]

  • 0

This is an array of objects showing a user uploading photos:

Array
(
    [12] => stdClass Object
        (
            [type] => photo
            [created] => 2010-05-14 23:36:41
            [user] => stdClass Object
                (
                    [id] => 760
                    [username] => mrsmith
                )

            [photo] => stdClass Object
                (
                    [id] => 4181
                )

        )

    [44] => stdClass Object
        (
            [type] => photo
            [created] => 2010-05-14 23:37:15
            [user] => stdClass Object
                (
                    [id] => 760
                    [username] => mrsmith
                )

            [photo] => stdClass Object
                (
                    [id] => 4180
                )

        )
)

However instead of showing:

  • mr smith uploaded one photo

  • mr smith uploaded one photo

I’d like to display:

  • mr smith uploaded two photos

by grouping similar items, grouping by user ID and them having added them within, let’s say 15 minutes of each other. So I’d like to get the array in this sort of shape:

Array
(
    [12] => stdClass Object
        (
            [type] => photo
            [created] => 2010-05-14 23:36:41
            [user] => stdClass Object
                (
                    [id] => 760
                    [username] => mrsmith
                )

            [photos] => Array
                (
                    [0] => stdClass Object
                          (
                           [id] => 4181
                          )

                     [1] => stdClass Object
                          (
                           [id] => 4180
                          )
                )

        )
)

preserving the first item of the group and it’s created time, and supplementing it with any other groupable photos and then unsetting any items that were grouped (so the final array doesn’t have key 44 anymore as it was grouped in with 12).

The array contains other actions than just photos, hence the original keys of 12 and 44. I just can’t figure out a way to do this efficiently. I used to use MySQL and PHP to do this but am trying to just use pure PHP for caching reasons.

Can anyone shed any insights? I thought about going through each item and seeing if I can group it with the previous one in the array but the previous one might not necessarily be relevant or even a photo. I’ve got total brain freeze 🙁

  • 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-14T23:13:03+00:00Added an answer on May 14, 2026 at 11:13 pm

    If the entries are ordered by date you can do the following:

    • Keep an array (let’s call it $foo) with all the photos in a 15 minute window. Use the array as a FIFO list (use array_shift to remove items and $foo[] = ... to add).
    • Iterate over the original array
      • Check the date of the current item and remove from the beginning of $foo all the entries whose date is more than 15 minutes less than the current item. Once you find an item that for something that happened less than 15 minutes ago, you can stop (it’s a one line for loop).
      • Iterate over the the entries in $foo
      • If a photo by the same person is found, then
        • Alter the reference stored in $foo so that the new data is added
        • Remove the current item from the original array
        • break from inner loop
      • If not
        • Add a reference to the current item to the end $foo with $foo = &$var.

    You may then reindex the original array with array_values to fill the gaps.

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

Sidebar

Related Questions

I have an objects array like this: Array ( [945] => member Object (
Trying to sort this array of objects according to (1) depth and (2) weight,
I have an ArrayCollection of objects. I'm passing this array to a horizontallist as
I have this code to sort an array of objects. The data in the
I have a map array with objects stuffed with variables looking like this: var
Let's say I have an array of objects [{href: 'some_uri', 'class': 'this-css-class'}, {href: 'another_uri',
I have an array list of objects and I am using this example to
I have an array of custom objects. MyCustomArr[]. I want to convert this to
Ok, I've an array of dummy objects containing property cgpath. This is called darkPathArray
I am trying to select an object from this array and print all of

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.