A more condensed way of doing the following loop?

Posted by kylex on Stack Overflow See other posts from Stack Overflow or by kylex
Published on 2010-06-10T18:10:17Z Indexed on 2010/06/10 18:13 UTC
Read the original article Hit count: 273

Filed under:
|
|

I have the following for-loop. It uses the values 0-6 form monday-sunday respectively.

Is there a more condensed way to do this? As opposed to listing out the if ($i=="day")

// $i = 0 is monday... $i = 6 is Sunday
for($i=0;$i<7;$i++){

    if ($i==0)
        echo ' <input name="repeat_on_week[]" type="checkbox" value="0"  /> Monday';
    if ($i==1)
        echo ' <input name="repeat_on_week[]" type="checkbox" value="1" /> Tuesday';
    if ($i==2)
        echo ' <input name="repeat_on_week[]" type="checkbox" value="2" /> Wednesday';
    if ($i==3)
       echo ' <input name="repeat_on_week[]" type="checkbox" value="3" /> Thursday';
    if ($i==4)
       echo ' <input name="repeat_on_week[]" type="checkbox" value="4" /> Friday';
    if ($i==5)
        echo ' <input name="repeat_on_week[]" type="checkbox" value="5" /> Saturday';
    if ($i==6)
        echo ' <input name="repeat_on_week[]" type="checkbox" value="6" /> Sunday';

}

© Stack Overflow or respective owner

Related posts about php

Related posts about loop