I have a question to looping several numbers together.
I've tried to do with two function below:
for ($x=28; $x <= 31; $x++){
echo $x.'<br>';
}
for($i=1; $i<6; $i++){
echo $i.'<br>';
}
But I want the script with a single step like:
for(){
// code
for(){
// code
}
}
And the final result, I try to implement it on the input option:
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
Hi if need to print only
`<option>28</option>`
<option>29</option>
<option>30</option>
<option>31</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
then can use below code
$start = 28;
$count = 31;
for ($x = $start; $x <=$count; $x++){
echo '<option>'.$x.'</option>';
if($x==31){
$count=6;
$x=0;
}
}
Increase your first loop by 1 and run the second loop within it
for ($x=28; $x <= 32; $x++)
{
if($x <= 31)
{
echo $x.'<br>';
}
else
{
for($i=1; $i<6; $i++)
{
echo $i.'<br>';
}
}
}
If you "... want to make a date in option 1-31, but I cut it from the middle for example 28-31 then 1-27 ... ", you may try with the next example, using just one for
loop:
<?php
$start = 28;
$count = 31;
for ($x = 0; $x < $count; $x++){
$n = ($start + $x <= $count) ? ($start + $x) : ($start + $x - $count);
echo $n.'<br>';
// or more complex output
//echo "<option>".$n."</option>";
}
?>