php - how to control interval of for loop? -


I have a number of $ 23 for the loop.

 For  ($ page = 0; $ page & lt; $ count; $ page ++) {echo $ page; }  

I want to substitute a page variable instead of one, rather than 10, so that when the $ page reverbs it, I want the result 10, 20, and not the last 23.

 For  ($ page = 0; $ page & lt; $ count; $ page + 10) {echo $ page; }  

When I do this, the loop continues continuously, 0 resonates. If someone has any advice, I would appreciate it. thank you in advanced.

 for  ($ page = 0; $ page & lt; $ count; $ page + = 10) {echo $ page; }  

Just your increment syntax should be slightly wrong (page + = not page + ) which is not actually updated The value of $ page var)

Alternatively you can use long form / more complex math:

 for  ( $ Page = 0; $ page & lt; $ count; $ page = $ page + 10) {$ page echo;  

Word of caution Ensure that you have the status of any category ( & lt; or & lt; = < / Code>) If you are resizing your step in this way, otherwise you can jump ahead of your situation (read ! = 23 ) and create a never-ending loop Are there. There is no problem for the way you wrote it, but there is something to consider.


Comments