Find all elements in array which have at | PHP program to find all elements in array which have atleast two greater elements itself . ; If current element is smaller than first then update both first and second ; If arr [ i ] is in between first and second then update second ; Driver code
< ? php function findElements ( $ arr , $ n ) { $ first = PHP_INT_MIN ; $ second = PHP_INT_MIN ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] > $ first ) { $ second = $ first ; $ first = $ arr [ $ i ] ; } else if ( $ arr [ $ i ] > $ second ) $ second = $ arr [ $ i ] ; } for ( $ i = 0 ; $ i < $ n ; $ i ++ ) if ( $ arr [ $ i ] < $ second ) echo $ arr [ $ i ] , " ▁ " ; } $ arr = array ( 2 , -6 , 3 , 5 , 1 ) ; $ n = count ( $ arr ) ; findElements ( $ arr , $ n ) ; ? >