If you're relatively new to programming, there's a term you might have heard floating around but not really understood - "refactoring". If you're interested in learning more about it and want a gentle introduction of how it works in PHP to help make your code better, check out this introductory video from Stefan Mischook.
In a nutshell: It is the process of code refinement - taking messy code and reorganizing it into much more manageable (cleaner) chunks. Refactoring is such an important part of coding, that I slap my programmers on back of the head, if they fail to refactor their code!
He talks about refactoring being something that's done constantly, not just later down the line. He also talks about when to refactor and suggests a few methods that you can use. You can watch the video either in the in-page player or over on YouTube for a larger size.