algorithm - Grouping php array items based on user and created time -


This user is an array of objects showing photos that upload:

  Array ( [12] = & gt; stdClass object ([type] => photo [created] => 2010-05-14 23:36:41 [user] => stdClass object ([ID] = & Gt; 760 [username] = & gt; Marcith) [Photo] => Study Class Object ([ID] => 4181)) [44] => Study Class Object ([type] = & Gt; photo [built] => 2010-05-14 23: 37: 15 [user] => Study Class Object ([ID] => 760 [User Name] => Merciteth) [Photo] => Stud Class Object ([ID] => 4180))  

However instead of showing:

  • MR Smith uploaded a photo

  • Mrs. Smith uploaded a photo

  • D:

    • MR Smith uploaded two messages

    grouping similar objects By creating a group based on user id and adding them in, we say that 1 5 minutes of each other so I would like to get the array in such a shape:

      array ([12] => StdClass object ([type] => photo [created] => 2010 -05-14 23:36:41 [user] => Study Class object ([ID] => 760 [user name] = & Gt; Mercieth) [Photo] => Array ([0] => stud class object ([ID] => 4181) [1] => stdClass object ([ID] => gt; ; 4180))  

    The first item in the group is preserving and it has been made time, and it is complementing it with any other groupable photos and then any Item that was grouped (Hence the last array does not have 44 now because it was grouped into 12).

    RRE has other verbs than just photos, so there are basic keys of 12 and 44. I can not understand a way to do it efficiently. I used MySQL and PHP to do this, but I'm just trying to use pure PHP for caching reasons.

    Can anyone leave any information? I thought about going through each item and if I can group with the previous one in the array, but the last one may not necessarily be relevant or can not be a picture too. I have total brain freeze: (

    If the order is ordered according to the date, You can:

    • Place an array with all photos in a 15 minute window (we call it $ foo .) As a FIFO list To remove the item ( and add the $ foo [] = ... ).
    • Unwind the original array
        < Li> Exit from the beginning of the current item and $ foo Take it, which is less than 15 minutes in comparison to the current item of all entries. Once you find an object that has been for less than 15 minutes, then you (this is a line for loop).
      • Write again on entries in $ foo
      • If a single person gets a photo,
      • $ Change the stored content in foo so that new data is added
      • Remove existing items from the original array
      • Inter Break from the loop
    • If
      • from $ foo to $ foo = & amp;
      • Can be added again.


    Comments