Last Updated: February 25, 2016
·
476
· guru ji

Tips for cron file (PHP)

1. for($i=0;$i<count($array);$i++) can be optimized to... 

$arrayCount = count($array);
for($i=0;$i<$arrayCount;$i++);


2. for($i=0;$i<$arrayCount;$i++){
$var =$array[$i]['key'];
    // progamming logic starts
    .....
    ....
    ...
    ..
    .
    // progamming logic ends

unset($var); // clearing cache for exact results

}

PHP has default cache mechanism and this creates problem in assigning values in a loop so its better to clear cache for exact results.

1 Response
Add your response

  1. I really doub it, this is a micro optimization.
  2. It depends on the contents of $array[$i]['key'] if is a scalar value then $var is a copy, if is an object is a reference to the same object...

Do you have any documentation or test about it ?

over 1 year ago ·