0

On Symfony blog, in support of Symfony being faster, it was mentioned that

for ($i = 0; $i<count($my_array); $i++)

is slower as compared to

for ($i = 0, $count = count($my_array); $i<$count; $i++)

The reason they had mentioned was "Because we measured". But what exactly is the reason for the latter being faster out of the two approaches mentioned above ?

0

1 Answer 1

4

The first 'for' calculates count of $my_array every iterate. The second 'for' calculates count once.

1
  • Now, that you have answered, it looks pretty obvious and I feel like an idiot to have asked this question in the very first place. Thanks a lot !:) Commented May 25, 2012 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.