Simplify and organized code in php