Compare sum of first N | Function that returns true if sum of first n - 1 elements of the array is equal to the last element ; Find the sum of first n - 1 elements of the array ; If sum equals to the last element ; Driver code
< ? php function isSumEqual ( $ ar , $ n ) { $ sum = 0 ; for ( $ i = 0 ; $ i < $ n - 1 ; $ i ++ ) $ sum += $ ar [ $ i ] ; if ( $ sum == $ ar [ $ n - 1 ] ) return true ; return false ; } $ arr = array ( 1 , 2 , 3 , 4 , 10 ) ; $ n = count ( $ arr ) ; if ( isSumEqual ( $ arr , $ n ) ) echo " Yes " ; else echo " No " ; ? >