How to count the consecutive duplicate values in an array?(如何计算数组中连续的重复值?)
问题描述
我有一个这样的数组:
我找到了函数 array_count_values()
,但它会将所有相同的值分组并计算出现次数,而不考虑连续序列中的中断.
I found the function array_count_values()
, but it will group all of the same values and count the occurrences without respecting breaks in the consecutive sequences.
如何对每组连续值进行分组并计算每个序列的长度?请注意,数字 1
、2
和 3
有两组序列.
How can I group each set of consecutive values and count the length of each sequence? Notice there are two sets of sequences for the numbers 1
, 2
, and 3
.
我期望生成的数据需要类似于:
The data that I expect to generate needs to resemble this:
推荐答案
只需手动即可:
这篇关于如何计算数组中连续的重复值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!