I’ve got it close but can’t figure it out. I have done:
$i = 1;
$direction = "up";
$v = 5;
$loop = 20;
$l = 1;
while ($l < $loop)
{
if($direction == "up")
{
$l++;
print $i;
$i++;
if ($i == $v){
$direction = "down";
}
} else {
$l++;
print $i;
$i = $i-1;
if ($i == 1){
$direction = "up";
}
}
}
?>
But it outputs 1,2,3,4,5,4,3,2,1,2,3,4,5,4 etc
When I need the last numbers to repeat next to each other i.e. 1,2,3,4,5,5,4,3,2,1,1,2,3,4,5
Cheers,
Michael Bray
Code:
<?php $i = 1;
$direction = "up";
$v = 5;
$loop = 20;
$l = 1;
while ($l < $loop)
{
if($direction == "up")
{
$l++;
print $i;
$i++;
if ($i == $v){
$direction = "down";
}
} else {
$l++;
print $i;
$i = $i-1;
if ($i == 1){
$direction = "up";
}
}
}
?>
But it outputs 1,2,3,4,5,4,3,2,1,2,3,4,5,4 etc
When I need the last numbers to repeat next to each other i.e. 1,2,3,4,5,5,4,3,2,1,1,2,3,4,5
Cheers,
Michael Bray