8 ms·
Two things caught me by surprise: for ($i = 0; $i < count($array); $i++) I thought PHP would be smart enough to optimise this. 'contains no dollar si
by pippy 14y ago
Two things caught me by surprise:
for ($i = 0; $i < count($array); $i++)
I thought PHP would be smart enough to optimise this.
'contains no dollar signs'
I practised the single vs. double quotes thing religiosity. I'm kind of embarrassed it doesn't actually make a difference.
- pcwalton 14y agoIn general you can't hoist the length check out of the loop because of the possibility that the length might change during the loop. Proving that the length doesn't change during the loop is quite difficult; in general this requires alias analysis.
- icelancer 14y ago"I thought PHP would be smart enough to optimise this." How? This is not a trivial optimization for a compiler.