Stores running count of ' x ' starting from the end
$ countX = array ( 0 , $ n , NULL ) ; $ count = 0 ; for ( $ i = $ n - 1 ; $ i >= 0 ; $ i -- ) { if ( $ str [ $ i ] == ' x ' ) $ count ++ ; $ countX [ $ i ] = $ count ; }