Freelance PHP Developer | Freelance PHP Programmer | PHP Freelance | Freelance Developer | PHP Freelancer | PHP Freelance Developers | PHP Developers | Freelance Developers | PHP Developer

[PHP] Optimize PHP code basic tips

php

As i mention in my echo vs print article, there are few basic tips to write a optimize PHP code. You are aware with echo and print that echo is faster so always prefer to use echo rather than use print. Now you use single quote as well as double quote to output simple string using echo statement. Single quote is faster than double quote, reason is that double quote is looking for varible first and than it will print the string while single quote will directly print the string on screen. Look at below code.

echo ‘Freelance PHP Developer: ‘ . $a; // prefer to use – faster
echo “Freelance PHP Developer: $a”; // avoid to use – slower

This is pretty interesting that if you have multiple parameters to show than using comma in echo statement instead of concat(dot) operator is faster. Generally developers including me are using concat(dot) operator to print two parameters.

echo ‘Freelance’, ‘ ‘, ‘PHP’, ‘ ‘, ‘Developer’; // prefer to use – faster
echo ‘Freelance’ . ‘ ‘ . ‘PHP’ . ‘ ‘ . ‘Developer’; // avoid to use – slower

Third tip is to use single quote for key while working with array. Reason is, if you do not use single quote for key than it will try to find the constant. If constant not exists than it will be consider as string and return the array element value. This will consume some time.

$phpdev['id'] // prefer to use – faster
$phpdev[id] // avoid to use – slower

      
Tweet
You can leave a response, or trackback from your own site.
    PHP Freelance | Freelance Developer | PHP Developer | PHP Freelancer | Freelance Developers | PHP Developers
    Freelance PHP Developer