Probability of a key K present in array | Function to find the probability ; find probability ; Driver Code
< ? php function kPresentProbability ( & $ a , $ n , $ k ) { $ count = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) if ( $ a [ $ i ] == $ k ) $ count ++ ; return $ count / $ n ; } $ A = array ( 4 , 7 , 2 , 0 , 8 , 7 , 5 ) ; $ K = 2 ; $ N = sizeof ( $ A ) ; echo round ( kPresentProbability ( $ A , $ N , $ K ) , 2 ) ; ? >