How to write better PHP code:-
I'm not going to offer you a recipe. Instead of that here are seven of the best practices I follow to write better PHP code:
- Use alternative PHP syntax in templates.
- Everything capsulated (separation of logic and display code; e.g. an MVC layout).
- Use a DB object, such as PDO.
- Debugging is your best friend. Helpful functions: var_dump(), die(). debug_print_backtrace(). Also review the PHP manual section on error handling.