Problem: You need to process each byte in the string separately. for example, calculate the number of vowels contained in a string. Solution: Use the for loop to traverse every byte of a string
Problem: You need to process each byte in the string separately. for example, calculate the number of vowels contained in a string.
Solution: Use the for loop to traverse every byte of a string
Function: for (expr1; expr2; expr3)
Statement
$ S = 'This is my blog, lostphp ,. com '; $ num = 0; for ($ I = 0, $ j = strlen ($ s); $ I <$ j; $ I ++) {if (strpos ('aeiouaeiou ', $ s [$ I]) {$ num ++ ;}} echo $ num;
Conclusion: The first expression (expr1) is evaluated unconditionally once before the start of the loop.
Expr2 is evaluated before each cycle starts. If the value is TRUE, the loop continues and the nested loop statement is executed. If the value is FALSE, the loop is terminated.
Expr3 is evaluated (executed) after each loop ).
Each expression can be null or multiple expressions separated by commas. In expression expr2, all expressions separated by commas are calculated, but only the last result is obtained. If expr2 is null, it means an infinite loop (like C, PHP considers its value TRUE ). This may not be as useful as imagined, because it is often expected that the break statement is used to end the loop rather than the true value of the for expression.