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.
Written by Gopinath J
Related protips
1 Response
- I really doub it, this is a micro optimization.
- 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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Related Tags
#php
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#