Copy
$num = array(
array('first'=> '1', 'second'=> '2', 'third'=> '3', 'fourth'=> '4'),
array('first'=> '5', 'second'=> '4', 'third'=> '2', 'fourth'=> '5'),
array('first'=> '1', 'second'=> '2', 'third'=> '3', 'fourth'=> '5'),
array('first'=> '1', 'second'=> '3', 'third'=> '2', 'fourth'=> '4'),
위와 같은 배열일때
1: 갯수
2: 갯수
3: 갯수
4: 갯수
5: 갯수
1~5까지 있는 갯수를 다시 제일 많은 값부터 정렬을 하고 싶습니다..어뜨케 해야할까요??
질문내용이 부족하면 댓글로 달아놓겠습니다..ㅠ
답변 3개 / 댓글 1개
채택된 답변
+20 포인트
as12as
3년 전
Copy
$num = array(
array('first'=> '1', 'second'=> '2', 'third'=> '3', 'fourth'=> '4'),
array('first'=> '5', 'second'=> '4', 'third'=> '2', 'fourth'=> '5'),
array('first'=> '1', 'second'=> '2', 'third'=> '3', 'fourth'=> '5'),
array('first'=> '1', 'second'=> '3', 'third'=> '2', 'fourth'=> '4')
);
$rst = $sort = [];
foreach ($num as $val) $rst = array_merge($rst, array_values($val));
$sort = array_count_values($rst);
arsort($sort);
print_r($sort);
결과:
Array
(
[2] => 4
[1] => 3
[3] => 3
[4] => 3
[5] => 3
)
답변에 대한 댓글 1개
3년 전
3년 전
3년 전
갯수가 각 배열의 first~fourth까지의 합인가요?
답변을 작성하려면 로그인이 필요합니다.
array_count_values