Loop to add previous three numbers for each number starting from 3 and then assign first , second , third to second , third , and curr to third respectively
for ( $ i = 3 ; $ i < $ n ; $ i ++ ) { $ curr = $ first + $ second + $ third ; $ first = $ second ; $ second = $ third ; $ third = $ curr ; echo $ curr , " " ; } }