Array
(
[0] => Array
(
[user] => 255825309,
[like] => 49
)
[1] => Array
(
[user] => 11998398,
[like] => 7
)
[2] => Array
(
[user] => 173173336,
[like] => 2
)
[3] => Array
(
[user] => 141009789,
[like] => 25
)
[4] => Array
(
[user] => 141009789,
[like] => 25
)
[5] => Array
(
[user] => 141009789,
[like] => 25
)
)
$newUserArray = [];
$newLikeArray = [];
foreach ($array as $idx => $item) {
$userId = $item['user'];
if (isset($newArray[$userId])) {
$newUserArray[$userId] = ($newArray[$userId] + 1);
} else {
$newUserArray[$userId] = 1;
}
$like = $item['like'];
$newLikeArray[$userId] = $like;
}
$mostPopularUserIdx = array_search(max($newUserArray), $newUserArray);
echo $newUserArray[$mostPopularUserIdx];
echo '<br/>';
echo $newLikeArray[$mostPopularUserIdx];
foreach ($arr as $key => $value){
if (!array_key_exists($value->user, $count) ) {
$count[$value->user] = 0;
$sum[$value->user] = 0;
}
$count[$value->user] += 1;
$sum[$value->user] += $value->like;
}
arsort($count);
var_dump(key($count));
echo '<BR>';
var_dump($sum[key($count)]);