1. If arr [ ind ] is added to obtain given val then val - arr [ ind ] should be obtainable from index ind - 1. 2. If arr [ ind ] is subtracted to obtain given val then val + arr [ ind ] should be obtainable from index ind - 1. Check for both the conditions .
if ( $ val - $ arr [ $ ind ] >= 0 && $ val + $ arr [ $ ind ] <= $ maxLimit ) {