Display 0 - 1000 - 0 each on a separate line I've tried this question on two forums and have been told this is the best place for this type of question. I'm trying to print from 0 to 1000 then back to 0 again (and all numbers in-between), printing 1000 only once. Also, each number must be on a separate line using vanilla PHP.
My current code is 60 characters long. Is there a way to do the same thing but in less characters?
PHP, 60 bytes

echo implode(&quot;&lt;p&gt;&quot;,array_merge(range(0,999),range(1000,0)));

Try it online!
PHP, 38 bytes

for(;$i-=1|$x|=$i/1001;)echo~$i,&quot;&lt;p&gt;&quot;;

Try it online!
A one-byte improvement by JoKing. The idea is that by decrementing $i instead of incrementing it, we can save on the minus in the 1|-$x construction by having $x become -1 instead of 1 as a signal. This is achieved by using $i/1001, which is 0 if $i&gt;-1001 and -1 otherwise. This would break even if not for the fact we can now use ~$i instead of $i-1.
PHP, 39 bytes

for(;$i+=1|-$x|=$i&gt;1e3;)echo$i-1,&quot;&lt;p&gt;&quot;;

Try it online!
In collaboration with primo on the code.golf discord.
The idea is to have a signal variable $x that is zero until $i hits 1000 then is 1 afterwards. We use the bitwise construction 1|-$x which is a shorter version of $x ? -1 : 1 to select whether to go upwards or downwards.