Making zero array by decrementing pairs of adjacent | PHP program to find if it is possible to make all array elements 0 by decrement operations . ; used for storing the sum of even and odd position element in array . ; if position is odd , store sum value of odd position in odd ; if position is even , store sum value of even position in even ; Driver Code
< ? php function isPossibleToZero ( $ a , $ n ) { $ even = 0 ; $ odd = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ i & 1 ) $ odd += $ a [ $ i ] ; else $ even += $ a [ $ i ] ; } return ( $ odd == $ even ) ; } $ arr = array ( 0 , 1 , 1 , 0 ) ; $ n = sizeof ( $ arr ) ; if ( isPossibleToZero ( $ arr , $ n ) ) echo " YES " ; else echo " NO " ; ? >