solved problem 8 in php