Neater code using a PHP function to do the job