PHP 최빈값 구하기 mode()

1 개요[ | ]

PHP 최빈값 구하기 mode()
function mode($arr) {
	$count_values = array_count_values($arr);
	$max = max($count_values);
	foreach( $count_values as $key => $count) if( $max == $count ) return $key;
}
var_dump( mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17]) ); # int(6)
var_dump( mode(['orange','banana','apple','orange','orange','apple']) ); # string(6) "orange"

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}