solved problem 4 in php