PHP code for problem 10 revised