Add some code optimization

Added some code optimization to general function: !empty instead of sizeof $array > 0, precount variable outside for loops and  foreach($aHash as $key => $val);  instead of while(list($key,$val) = each($aHash));
In the original line, $n is executed once and is never repeated. There is no need for this change. Please revert this change style. Thanks!