Find Surpasser Count of each element in array | Function to find surpasser count of each element in array ; stores surpasser count for element arr [ i ] ; Function to print an array ; Driver Code
< ? php function findSurpasser ( $ arr , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ count = 0 ; for ( $ j = $ i + 1 ; $ j < $ n ; $ j ++ ) if ( $ arr [ $ j ] > $ arr [ $ i ] ) $ count ++ ; echo $ count , " " ; } } function printArray ( $ arr , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo $ arr [ $ i ] , " ▁ " ; echo " STRNEWLINE " ; } $ arr = array ( 2 , 7 , 5 , 3 , 0 , 8 , 1 ) ; $ n = count ( $ arr ) ; echo " Given ▁ array ▁ is ▁ STRNEWLINE " ; printArray ( $ arr , $ n ) ; echo " Surpasser ▁ Count ▁ of ▁ array ▁ is ▁ STRNEWLINE " ; findSurpasser ( $ arr , $ n ) ; ? >