solve problem 12 in php