함수 array_count_values()

uniq -c
array_count_values

1 Bash[ | ]

ARR=(1 "hello" 1 "world" "hello")
for VALUE in "${ARR[@]}"; do
	echo $VALUE
done | sort | uniq -c

2 POSIX Shell[ | ]

ARR="1 hello 1 world hello"
for VALUE in $ARR
do
        echo $VALUE
done | sort | uniq -c

3 C[ | ]

4 PHP[ | ]

$arr = [1, 'hello', 1, 'world', 'hello'];
print_r(array_count_values($arr));

5 Python[ | ]

import collections
lst = [1, 'hello', 1, 'world', 'hello']
print( collections.Counter(lst) )

6 Perl[ | ]

my %cnt;
my @lst = (1, 'hello', 1, 'world', 'hello');
$cnt{$_}++ for @lst;
print %cnt;

7 R[ | ]

v <- c(1, 'hello', 1, 'world', 'hello')
table(v)

8 SQL[ | ]

8.1 MySQL[ | ]

mysql> SELECT * FROM array;
+-------+
| value |
+-------+
| 1     |
| hello |
| 1     |
| world |
| hello |
+-------+
5 rows in set (0.00 sec)
mysql> SELECT value, COUNT(*) FROM array GROUP BY value;
+-------+----------+
| value | COUNT(*) |
+-------+----------+
| 1     |        2 |
| hello |        2 |
| world |        1 |
+-------+----------+
3 rows in set (0.00 sec)

9 같이 보기[ | ]

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