Software engineering engineer at a national public broadcaster. Best practices / developer experience / agile / diversity and inclusion / psychological safety
Depending on the size of your list, count() can indeed be very expensive if you do it repeatedly. There’s no need to define it outside of your for though:
And while descriptive variable names are usually a good thing, $i is kind of an exception to that rule. Its usage has become so idiomatic across languages that anyone who sees for ($i = 0; $i < $someNumber; ++$i) instantly understands what its purpose is, especially since it is virtually always used to access an array index (as in the example above).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Neat explanations!
Depending on the size of your list,
count()
can indeed be very expensive if you do it repeatedly. There’s no need to define it outside of yourfor
though:And while descriptive variable names are usually a good thing,
$i
is kind of an exception to that rule. Its usage has become so idiomatic across languages that anyone who seesfor ($i = 0; $i < $someNumber; ++$i)
instantly understands what its purpose is, especially since it is virtually always used to access an array index (as in the example above).