Initial solution for Problem 3 in PHP