Minimum and Maximum element of an array which is divisible by a given number k | Function to find the minimum element ; Function to find the maximum element ; Driver code
< ? php function getMin ( $ arr , $ n , $ k ) { $ res = PHP_INT_MAX ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] % $ k == 0 ) $ res = min ( $ res , $ arr [ $ i ] ) ; } return $ res ; } function getMax ( $ arr , $ n , $ k ) { $ res = PHP_INT_MIN ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] % $ k == 0 ) $ res = max ( $ res , $ arr [ $ i ] ) ; } return $ res ; } $ arr = array ( 10 , 1230 , 45 , 67 , 1 ) ; $ k = 10 ; $ n = sizeof ( $ arr ) ; echo " Minimum ▁ element ▁ of ▁ array ▁ which ▁ is ▁ " . " divisible ▁ by ▁ k : ▁ " , getMin ( $ arr , $ n , $ k ) , " STRNEWLINE " ; echo " Maximum ▁ element ▁ of ▁ array ▁ which ▁ is ▁ " . " divisible ▁ by ▁ k : ▁ " , getMax ( $ arr , $ n , $ k ) ; ? >