PHP solution to problem 25