solved problem 3 in php