The value of second element must be less than equal to n / 2
for ( $ j = $ i + 1 ; $ j <= $ n / 2 ; $ j ++ ) { $ k = $ n - $ i - $ j ; if ( $ i * $ i + $ j * $ j == $ k * $ k ) { echo $ i , " , ▁ " , $ j , " , ▁ " , $ k ; return ; } } } echo " No ▁ Triplet " ; }