View:    Discussions (0) Snips (4) Discovered by mustafadalci

Snips

Snipd by mustafadalci 1 year, 8 months ago    [ reply or start a discussion ]


4. Drop those Brackets




Drop Brackets



Dropping brackets saves space and time in your code.



Much like using shortcuts when writing else functions, you can also save some characters in the code by dropping the brackets in a single expression following a control structure. Evolt.org has a

handy example

showcasing a bracket-less structure.








  1. if


     (


    $gollum


     == 


    'halfling'


    ) {  






  2. $height


     --;  





  3. }  






This is the same as:








  1. if


     (


    $gollum


     == 


    'halfling'





    $height


     --;  







You can even use multiple instances:








  1. if


     (


    $gollum


     == 


    'halfling'





    $height


     --;  






  2. else


     


    $height


     ++;   





  3.   





  4. if


     (


    $frodo


     != 


    'dead'


    )  






  5. echo


     


    'Gosh darnit, roll again Sauron'


    ;  





  6.   





  7. foreach


     (


    $kill


     


    as


     


    $count


    )  






  8. echo


     


    'Legolas strikes again, that makes'


     . 


    $count


     . 


    'for me!'


    ;  





7. Memcached



Memcached




Memcached is an excellent database caching system to use with PHP.





While there are tons of caching options out there,



Memcached



keeps topping the list as



the most efficient for database caching



. It’s not the easiest caching system to implement, but if you’re going to build a website in PHP that uses a database, Memcached can certainly speed it up. The caching structure for Memcached was first built for the PHP-based blogging website LiveJournal.




PHP.net has an excellent tutorial on



installing and using memcached



with your PHP projects.

Close
What do you think? How do you feel?
Feedback can mold Snipd. Make Snipd your baby!