solved problem 5 in php