try
$arr = array("test", "test", "hello", "test", "world", "world", "world", "hello", "test");
$prev = '';
$results = [];
$j = 0;
foreach ($arr as $i => $v) {
if ($v != $prev) {
$j = $i;
$results[$j] = 1;
$prev = $v;
}
else {
$results[$j]++;
}
}
foreach ($results as $k => $v) {
echo "$arr[$k] : $v <br>";
}
Result:
test : 2
hello : 1
test : 1
world : 3
hello : 1
test : 1