Which method is more efficient?
The Longer, Simpler, Manual Way:
$theNewLW = $theteam['leftwing'];
$theNewC = $theteam['center'];
$theNewRW = $theteam['rightwing'];
$theNewLD = $theteam['leftdefense'];
$theNewRD = $theteam['rightdefense'];
$theLWskill = ceil(((($this->player[$theNewLW]['passing']*.09)+($this->player[$theNewLW]['speed']*.04)+($this->player[$theNewLW]['agility']*.04)+($this->player[$theNewLW]['offense']*.08)*$this->player[$theNewLW]['morale'])/100)+.7);
$theCskill = ceil(((($this->player[$theNewC]['passing']*.09)+($this->player[$theNewC]['speed']*.04)+($this->player[$theNewC]['agility']*.04)+($this->player[$theNewC]['offense']*.08)*$this->player[$theNewC]['morale'])/100)+.7);
$theRWskill = ceil(((($this->player[$theNewRW]['passing']*.09)+($this->player[$theNewRW]['speed']*.04)+($this->player[$theNewRW]['agility']*.04)+($this->player[$theNewRW]['offense']*.08)*$this->player[$theNewRW]['morale'])/100)+.7);
$theLDskill = ceil(((($this->player[$theNewLD]['passing']*.09)+($this->player[$theNewLD]['speed']*.04)+($this->player[$theNewLD]['agility']*.04)+($this->player[$theNewLD]['offense']*.08)*$this->player[$theNewLD]['morale'])/100)+.7);
$theRDskill = ceil(((($this->player[$theNewRD]['passing']*.09)+($this->player[$theNewRD]['speed']*.04)+($this->player[$theNewRD]['agility']*.04)+($this->player[$theNewRD]['offense']*.08)*$this->player[$theNewRD]['morale'])/100)+.7);
Or the shorter, complicated, automatic way:
$plist = array("leftwing", "center", "rightwing", "leftdefense", "rightdefense");
for($i=0;$i<$theteam['players'];$i++){
$theskill[$plist[$i]] = $theLWskill = ceil(((($this->player[$theteam[$plist[$i]]]['passing']*.09)+($this->player[$theteam[$plist[$i]]]['speed']*.04)+($this->player[$theteam[$plist[$i]]]['agility']*.04)+($this->player[$theteam[$plist[$i]]]['offense']*.08)*$this->player[$theteam[$plist[$i]]]['morale'])/100)+.7);
}
When I microTime() them ... the second one seems much quicker:
on average It took 0.00018 seconds to calculate the passing vs
It took 0.00011 seconds to calculate the passing
I've heard it's best to use as little code as possible (arrays/loops) AND I've also heard to write the code simple and long, cuz you only need to do it once...
...anyone who knows about advanced PHP and the workings of it, please comment, thx...