@veryYoung

Как вывести самый часто встречаемый элемент в массиве?

есть массив данных, с вк, полученный wall.getReposts, как получить, так сказать, топ репостера, то есть как вывести элемент массива (from_id), значение которого чаще всего встречается в массиве?
один элемент массива
spoiler
Array (
[items] => Array (
[0] => Array (
[id] => 791
[from_id] => 4092108
[to_id] => 4092108
[date] => 1560265172
[post_type] => post
[text] =>
[copy_history] => Array (
[0] => Array (
[id] => 4637
[owner_id] => -758967
[from_id] => -758967
[date] => 1560175291
[post_type] => post
[text] => текст поста
[attachments] => Array (
[0] => Array (
[type] => photo
[photo] => Array (
[id] => 4562433
[album_id] => -7
[owner_id] => -758967
[user_id] => 100
[sizes] => Array (
[0] => Array (
[type] => m [url] => https://pp.userapi.com/c854128/v854128765/664de/i9...
[width] => 130
[height] => 86
)
[1] => Array (
[type] => o
[url] => https://pp.userapi.com/c854128/v854128765/664e0/9z...
[width] => 130
[height] => 87
)
[2] => Array (
[type] => p
[url] => https://pp.userapi.com/c854128/v854128765/664e1/CQ...
[width] => 200
[height] => 133
)
[3] => Array (
[type] => q
[url] => https://pp.userapi.com/c854128/v854128765/664e2/8I...
[width] => 320
[height] => 213
)
[4] => Array (
[type] => r
[url] => https://pp.userapi.com/c854128/v854128765/664e3/l7...
[width] => 510
[height] => 340
)
[5] => Array (
[type] => s
[url] => https://pp.userapi.com/c854128/v854128765/664dd/ST...
[width] => 75
[height] => 50
)
[6] => Array (
[type] => x
[url] => https://pp.userapi.com/c854128/v854128765/664df/Cq...
[width] => 585
[height] => 389
)
)
[text] =>
[date] => 1560178731
[access_key] => 450a267bb30f7
)
)
)
[post_source] => Array (
[type] => vk
)
)
)
[post_source] => Array (
[type] => vk
)
[comments] => Array (
[count] => 0
[can_post] => 1
[groups_can_post] => 1
)
[likes] => Array (
[count] => 0
[user_likes] => 0
[can_like] => 1
[can_publish] => 1
)
[reposts] => Array (
[count] => 0

[
user_reposted] => 0
)
[views] => Array (
[count] => 10
)
[is_favorite] =>
)
)
[profiles] => Array (
[0] => Array (
[id] => 409210
[first_name] => Имя
[last_name] => Фамилия
[is_closed] =>
[can_access_closed] => 1
[sex] => 1
[screen_name] => id4092108
[photo_50] => https://pp.userapi.com/c636631/v636631873/4e074/ZT...
[photo_100] => https://pp.userapi.com/c636631/v636631873/4e073/rW...
[online] => 0
)
)
[groups] => Array (
[0] => Array (
[id] => 758967
[name] => test
[screen_name] => ugfuigfcuyg
[is_closed] => 0
[type] => group
[is_admin] => 1
[admin_level] => 3
[is_member] => 1
[is_advertiser] => 1
[photo_50] => https://sun1-85.userapi.com/c638127/v638127093/55f...
[photo_100] => https://sun1-86.userapi.com/c638127/v638127093/55f...
[photo_200] => https://sun1-15.userapi.com/c638127/v638127093/55f...
)
)
)
1
  • Вопрос задан
  • 173 просмотра
Пригласить эксперта
Ответы на вопрос 2
dollar
@dollar
Делай добро и бросай его в воду.
Посчитать
$arr = [1,2,3,4,5,5,4,1,2,1,2,5,2,2,3,2];
$cnt = [];
foreach ($arr as $val) { //Считаем
	$cnt[$val] = @$cnt[$val] + 1;
}
print_r($cnt);

$answer = 0;
$max = 0;
foreach ($cnt as $key=>$val) if ($val > $max) { //Ищем максимум
    $max = $val;
    $answer = $key;
}
print_r('Answer: '.$answer);
Ответ написан
@hesy
Привет, актуально?

https://3v4l.org/DHrDI
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы