I have created this code but i think there's a problem with it
<?php
$array = array("test", "test", "hello", "test", "world", "world", "world", "hello", "test");
$j=1;
for( $i= 0 ; $i <= 7 ;$i++ ){
if ($array[$i] === $array[$i+1])
{
echo $j .= $j+1;
}
else
{
echo "1";
}
}?>
output = 1211112131213121411
not 2,1,1,3,1,1 😅
Thank you Barand;
This my array
$Array = array("test", "test", "hello", "test", "world", "world", "world", "hello", "test");
Well, i would like to show a list with adjacent duplicates for example the word test 2 not 4 duplicates
and finally the output will be like this 2,1,1,3,1,1
the problem that array_count_values show the all duplicates, i would like to show the adjacent duplicates
Hello;
I would like to do the following operation;
Count duplicate (adjacent)
my code
<?php
$Array = array("test", "test", "hello", "test", "world", "world", "world", "hello", "test");
for( $i= 0 ; $i <= 6 ;$i++ ) {
$j=1;
if ($Array[$i] === $Array[$i+1]) {
$j+=$j;
echo $j;
}
?>
and showing something like 2,1,1,3,1,1
Thanks
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.