Elements greater than the previous and next element in an Array | Function to print elements greater than the previous and next element in an Array ; Traverse array from index 1 to n - 2 and check for the given condition ; Driver Code
< ? php function printElements ( $ arr , $ n ) { for ( $ i = 1 ; $ i < $ n - 1 ; $ i ++ ) { if ( $ arr [ $ i ] > $ arr [ $ i - 1 ] and $ arr [ $ i ] > $ arr [ $ i + 1 ] ) echo $ arr [ $ i ] . " ▁ " ; } } $ arr = array ( 2 , 3 , 1 , 5 , 4 , 9 , 8 , 7 , 5 ) ; $ n = sizeof ( $ arr ) ; printElements ( $ arr , $ n ) ;