title: Sudoku solving/generating algorithm in PHP
body: <p>I'm having trouble with a specific part of my algorithm and was hoping someone has an idea what I'm doing wrong.</p>
  
  <p>My program basically works like this:</p>
  
  <p>Create 81 empty cells, fill each cell step per step while checking if it's valid there. </p>
  
  <p>I have 3 valid checks and the horizontal valid check (if numbers are double or more in 1 line) is already giving me trouble.</p>
  
  <p>This is my function:</p>
  
  <pre><code>private function isValidHorizontal($index)
      {
          for ($i = 0; $i &lt; 81; $i += 9){
  
              $firstIndex = $i * 9;
              $lastIndex = 9 * ($i + 1) - 1;
  
              // fisrt loop tracking fowards, 2nd loop tracking backwards
              if ($index &gt;= $i &amp;&amp; $index &lt;= $lastIndex) {
                  for ($j = 0; $j &lt;= $lastIndex; $j++) {
                      if ($this-&gt;cell[$index]-&gt;getValue() == $j) {
                          return false;
                      }
                  }
                  for ($k = 0; $k &gt;= $firstIndex; $k--){
                      if ($this-&gt;cell[$index]-&gt;getValue() == $j) {
                          return false;
                      }
                  }
              }
          }
  
          return true;
      }
  </code></pre>
  
  <p><code>$index</code> is the position of the cell so when <code>$index = 0</code> that would be the very first cell. Last cell would be <code>$index = 80</code></p>
  
  <p><code>$this-&gt;cell[$index]-&gt;getValue()</code> returns an int number i checked so I'm getting the value correctly. </p>
  
  <p>The problem it somehow never returns true</p>
  
  <p>Any Ideas? obviously this is just part of the code, if you need more to help, write a comment and I'll edit :)</p>