|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-01-02 02:21 UTC] m dot dziczkowski at prokonto dot pl
Description:
------------
I had found a bug in the for loop. Increasing value is working, but decreasing isn't. See code
Test script:
---------------
// Working
for ($y = 1945; $y <= 2015; $y++)
{
// some code to do
}
// Not working
for ($y = 2015; $y <= 1945; $y--)
{
// some code to do
}
// sames happens if I replace (in the not working one) the "2015" with a variable (for example: $year = 2015; or $year = date("Y");
Expected result:
----------------
displayed values from 2015 to 1945
Actual result:
--------------
none
Patchesnone (last revision 2016-01-02 02:23 UTC by m dot dziczkowski at prokonto dot pl)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 23:00:01 2026 UTC |
/* The select bellow don't shows other options then "-- select --" */ // code trunchated for securuty reasons <select name = "year"> <option value = "#">-- Select --</option> <? for ($y = 2015; $y <= 1945; $y--) { echo "<option value = \"$y\">$y</option>"; } ?> </select> /* When I done a small change into: */ <select name = "year"> <option value = "#">-- Select --</option> <? for ($y = 1945 $y <= 2015; $y++) { echo "<option value = \"$y\">$y</option>"; } ?> </select> /* the code started to work */Your example is flawed, the second "not working" loop will not loop because $y is never "less than or equal to" 1945, it starts off at 2015. I think you meant to do: for ($y = 2015; $y >= 1945; $y--) { // some code to do }