Sum of array elements that is first continuously increasing then decreasing | Efficient PHP method to find sum of the elements of array that is halfway increasing and then halfway decreassing ; Driver code
< ? php function arraySum ( $ arr , $ n ) { $ x = ( $ n + 1 ) / 2 ; return ( $ arr [ 0 ] - 1 ) * $ n + $ x * $ x ; } $ arr = array ( 10 , 11 , 12 , 13 , 12 , 11 , 10 ) ; $ n = sizeof ( $ arr ) ; echo ( arraySum ( $ arr , $ n ) ) ; ? >