Euler Project 14 - Longest Collatz Sequence in PHP
Redoing tons of work

Consider a number like 100. By the time $n gets to 100, we will have already done the work for $n == 50 (which has a length of 25). So rather than simply seeing that the result for $n was 25, and adding 1 (since we're one step away from that) -- we have to recalculate all 26 steps from scratch.

For that matter, we'd've already done $n as 33, so just by having gotten to 100, we should already know that it's at 26 without doing any work. 

Save your state as you go along - this is known as memoization. Given that the resulting longest chain is of length 525, that's a lot of work that we'll end up saving. Just that one chain will end up with 525 operations instead of 138,075...