There is a class php

stdClass Object( [0] => stdClass Object ( [id] => 4332 [user_id] => 3 [useru_id] => 2 [date] => 1474045582 ) [1] => stdClass Object ( [id] => 4333 [user_id] => 3 [useru_id] => 2 [date] => 1474045583 ) [2] => stdClass Object ( [id] => 4334 [user_id] => 4 [useru_id] => 2 [date] => 1474045591 ) [3] => stdClass Object ( [id] => 4336 [user_id] => 3 [useru_id] => 2 [date] => 1474045594 ) ) 

It is necessary to group it by useru_id (it is the same for everyone = 2) and so that the output knows the number of grouped keys (for user_id = 3 it turns out in the sum 3, for user_id = 4 it turns out in the sum 1).

It should turn out like this

 stdClass Object ( [3] => stdClass Object ( [id] => 4336 [user_id] => 3 [useru_id] => 2 [date] => 1474045594 [count] => 3 ) [4] => stdClass Object ( [id] => 4334 [user_id] => 4 [useru_id] => 2 [date] => 1474045591 [count] => 1 ) ) 

Closed due to the fact that off-topic participants are Alexey Shimansky , aleksandr barakin , Kirill Stoianov , αλεχολυτ , user207618 26 Sep '16 at 4:51 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Alexey Shimansky, αλεχολυτ, Community Spirit
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

     $summary = array(); $counter = array(); foreach($array as $row){ if(isset($counter[$row['user_id']])) $counter[$row['user_id']]++; else $counter[$row['user_id']] = 1; $summary[$row['user_id']][] = $row; } 

    In the $summary group, in $counter size of each group.

    • Thanks, it works this way, but you need to get 1 array (you have $ 2 summary and $ counter). I do not know how to insert the code, but you need to get it like this: stdClass Object ([3] => stdClass Object ([id] => 4336 [user_id] => 3 [useru_id] => 2 [date] => 1474045594 [count] => 3) [4] => stdClass Object ([id] => 4334 [user_id] => 4 [useru_id] => 2 [date] => 1474045591 [count] => 1)) - skillful
    • @skillful I edited your question. How then should all the other fields be selected? id , useru_id and date ? - rjhdby