Php doesn’t work condition

I don’t understand why the program doesn’t work correctly. It should be:
when the program find a number between 1 and 18 have to put a negative symbol to next, if is between 19 and 36 a positive symble like 1- 30+ 18- and so on.
After that, find the combinations for example, when finds 3 negative symbols add another negative next the last symbol like this
18-
10-
12- –

the others combination are

the first

30+

29+

19+ –

the second

18-

7-

1- –

third

29+

19+ +

fourth

7-

10- +

The problem is: I don’t understand why sometimes the programs prints this

28+

29+

31+ –

35+

24+

35+

36+ –

when It should be

28+

29+

31+ –

35+

24+

35+

36+

or print

10-

34- +

29-

when it should be

10-

34-

29- +

<html>
<body>
    <?php

    $fixed = 500;

for ($z = 0; $z <$fixed; $z++) {
      //dovrebbe memorizzare tutti i valori
        $num = rand(1,36);
        $container[$z] = $num;

} 



if ($z = $fixed) {




for ($i = 0; $i <$fixed; $i++){


if ($container[$i] < 19 AND $container[$i+1] < 19 AND $container[$i+2] < 19) {// - - -   -

print ($container[$i]."- <br>");
$i++;
print ($container[$i]."- <br>"); 
$i++;
print ($container[$i]."- - <br>");

do {

    $i++;
    print ($container[$i]."- <br>"); 

} while ($container[$i] > 18);

} 

elseif ($container[$i] < 19 AND $container[$i++] < 19) { // - -    +
print ($container[$i]."- <br>"); 
$i++;
print ($container[$i]."- + <br>");
$i++;

}

elseif ($container[$i] > 18 AND $container[$i+1] > 18 AND $container[$i+2] > 18) {// + + +   -

print ($container[$i]."+ <br>");
$i++;
print ($container[$i]."+ <br>"); 
$i++;
print ($container[$i]."+ - <br>");

do {

    $i++;
    print ($container[$i]."+ <br>"); 

} while ($container[$i] < 19);

}

elseif ($container[$i] > 18 AND $container[$i+1] > 18) { // + +    +

print ($container[$i]."+ <br>");
$i++;
print ($container[$i]."+ +<br>"); 
$i++;

} 


elseif ($container[$i] < 19) { 
    print ($container[$i]."- <br>");
    $i++;
}
else {
    print ($container[$i]."+ <br>");
    $i++;
}

}  // FOR
} // IF
    ?>
 </body>
</html>


Source: php

Leave a Reply