PHP Coding Tips

Make your code more beautiful and optimized
1. Makes the the HTML tags and control structures aligned.

2. Use conditional operator (? :) instead of simple "if else" .

3. Use switch instead of "if else" where it suits which leads to faster execution.

4. Frequently using set of codes define as a function and call them wherever that functionality is needed, so that the redundancy of code can be avoided.

5. Use AJAX for loading dynamic content instead of refreshing the entire page.

6. Use the meaningful variable names according to its purpose which improves the readability and makes the code easy to understand.

7. Split the lengthy line into multiple lines so that the user can get an overall view without the horizontal scroll. Recommended number of  characters per line is 80. For sql statement, it will be more convenient if splits with each sql clauses like the following so that less chance to miss any joins or group by clauses while rechecking the logic but also make sure that it does not exceeds 80.

     $sql = "SELECT u.name, ua.address
                  FROM user u
                  INNER JOIN user_address
                  ON ua.user_id = u.id
                  WHERE u.school = 1                 
                  GROUP BY u.id
                  ORDER BY u.join_date";

1 comment:

Technologies

1. Nodejs
  • Express
  • Loopback
  • SailsJs
2. Angular
  • 2
  • 4
  • 5
  • 8
3. JQuery
4. PHP
  • LAMP
  • Codeigniter
  • Lumen
5. Database
  • MySQL
  • PostgreSQL
  • MongoDB
6. Artificial Intelligence
  • IBM Watson API
7. Amazon
  • S3
  • EC2
  • SES
  • ELB
8. REST & SOAP API integrations
9. Push notifications
  • FCM - Android
  • APNS - IOS
10. RETS(Real estate domain) servers
11. Standard Implementations
  • 508
  • LTI