The point about the speed in loops is, that the middle and the last expression are executed EVERY time it loops.
So you should try to take everything that doesn't change out of the loop.
Often you use a function to check the maximum of times it should loop. Like here:

This note should might be under the "strlen" manual page, but there is a better chance for more paying attention here (nevertheless I have made a short note over there allso).

A loop function that test for the string length at each iteration takes forever (possibly due to "strlen" searches for the C-style string terminator - a binary 0 - every time..

So loops like this, using "strlen" in the for...

for ($i = 0; $i < strlen($crc); $i++) .....

Will benefit tremendously in speed by a short step that saves the string length once and use that in the loop.

$clen = strlen($crc);

for ($i = 0; $i < $clen ; $i++) .....

Note: as a real hard-core programmer You are aware, that this is only valid if you don't change the string content inside the loop (and hereby allso the length). If the change is only occationly , You could just refresh the length variable or else just live with a quite slow loop.

This "discovery" was made from using an example of 16 bit crc calculation over at the "crc32" function manual page, that do exactly that..

For those who are having issues with needing to evaluate multiple items in expression two, please note that it cannot be chained like expressions one and three can. Although many have stated this fact, most have not stated that there is still a way to do this: