this is a question that I've been wondering about for a while and hope you guys might know the answer.
Lets say I have the following for loop:
for ($i = 0; $i < count($fields); $i++)
{
//do stuff
}
My question is, does PHP have to recalculate the count of $fields every time it iterates to find out if it reached the end or does it "store" it somewhere and knows how many iterations need to be done before that.
Essentially, is it better for performance to do the following:
$max_fields = count($fields)
for ($i = 0; $i < $max_fields; $i++)
{
//do stuff
}
or it doesnt matter?
Also is the behavior same for 'while' loops too?
Thanks a lot!