₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,327,197 members, 8,429,766 topics. Date: Friday, 19 June 2026 at 12:07 PM

Toggle theme

Grandtheft's Posts

Nairaland ForumGrandtheft's ProfileGrandtheft's Posts

1 (of 1 pages)

ProgrammingRe: Some optimization tips for php by grandtheft(op): 8:51am On Sep 21, 2013
Use str function over most regex functions. Except you really require a regex.
ProgrammingRe: Some optimization tips for php by grandtheft(op): 8:23am On Sep 21, 2013
Also do not do mysql queries in a loop, you can store all the queries in a variable in the loop then do the query outside the loop
ProgrammingRe: Some optimization tips for php by grandtheft(op): 6:47am On Sep 21, 2013
pc guru: so if am to understand you, in order to gain performance i should write all my codes in one file and not use classes, no thanks __autoload and SPLAutoloaders only activate when a class is called, i haven't encountered any performance issue on my part here besides its PSR-0 its the standard all my projects at work are OOP anyway so i don't know much about procedural projects.
he didn't say All you code.
ProgrammingRe: Some optimization tips for php by grandtheft(op): 7:02am On Sep 20, 2013
4)Rather than search an array for a value. Why not make the value the key then use the isset method ?. Here is what am saying:
<?php
$arr = array('apple' => 1, 'pineapple' => 1, 'orange' => 1, 'mango' => 1, 'pawpaw' => 1);
echo (isset($arr[$_GET['fruitname']]) ? 'Fruit Found' : 'Fruit Not Found');
?>
that is better, we all know isset is very fast. That was the same technique i used to build the unofficial .

5)copying variables just because you want a shorter name is totally wrong. Except you have a reason, because it consumes more space for nothing.
ProgrammingSome optimization tips for php by grandtheft(op):
1) ++$i is faster than $i++. You should use this is scenarios where it doesn't matter if you do a post or pre increment, because both of they are not the same. Same applies to pre decrement and post decrement.
2)Single quotes is faster than double quote because php searches for variables in a double quote. If you don't have variables in the double quotes consider changing it to single quotes.
3) for($i = 0; $i < count($arr); $i++) { is very bad because the count function gets called on each iteration. Rather declare a variable outside the loop like this: $count = count($arr); for($i = 0; $i < $count; $i++) {

1 (of 1 pages)