Check if the number is even or odd whose digits and base ( radix ) is given | Function that returns true if the number represented by arr [ ] is even in base r ; If the base is even , then the last digit is checked ; If base is odd , then the number of odd digits are checked ; To store the count of odd digits ; Number is odd ; Driver code
< ? php function isEven ( $ arr , $ n , $ r ) { if ( $ r % 2 == 0 ) { if ( $ arr [ $ n - 1 ] % 2 == 0 ) return true ; } else { $ oddCount = 0 ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { if ( $ arr [ $ i ] % 2 != 0 ) $ oddCount ++ ; } if ( $ oddCount % 2 == 0 ) return true ; } return false ; } $ arr = array ( 1 , 0 ) ; $ n = Count ( $ arr ) ; $ r = 2 ; if ( isEven ( $ arr , $ n , $ r ) ) echo " Even " ; else echo " Odd " ; ? >