try all subarrays starting with ' i '
for ( $ j = $ i + 1 ; $ j <= $ n ; $ j ++ ) { if ( $ curr_sum == $ sum ) { echo " Sum ▁ found ▁ between ▁ indexes ▁ " , $ i , " ▁ and ▁ " , $ j - 1 ; return 1 ; } if ( $ curr_sum > $ sum $ j == $ n ) break ; $ curr_sum = $ curr_sum + $ arr [ $ j ] ; } } echo " No ▁ subarray ▁ found " ; return 0 ; }