Count consecutive pairs of same elements | Function to return the count of consecutive elements in the array which are equal ; If consecutive elements are same ; Driver code
< ? php function countCon ( $ ar , $ n ) { $ cnt = 0 ; for ( $ i = 0 ; $ i < $ n - 1 ; $ i ++ ) { if ( $ ar [ $ i ] == $ ar [ $ i + 1 ] ) $ cnt ++ ; } return $ cnt ; } $ ar = array ( 1 , 2 , 2 , 3 , 4 , 4 , 5 , 5 , 5 , 5 ) ; $ n = sizeof ( $ ar ) ; echo countCon ( $ ar , $ n ) ; ? >