PHP Undefined offset: -1 in comparison loop
<p>I am receiving this error <strong>Undefined offset: -1.</strong> </p>

<p>I am pretty sure it is because I am comparing a value of an array index with the value of the previous index, so on the first iteration its failing because there is no -1 index.</p>

<pre><code>for ($i=0; $i&lt;$rows_n; $i++) 
{
    formatTR($i, $rows, 'YEAR');
}


// Function
function formatTR($i, $rows, $year) 
{

    if ($rows[$year][$i] != $rows[$year][$i-1] ) {
        print "&lt;tr class='header-year-tr'&gt;&lt;td colspan='2'&gt;{$rows[$year][$i]}&lt;/td&gt;&lt;/tr&gt;";
    }

    print "&lt;tr&gt;";
}
</code></pre>

<p>The function checks to see if the previous value of $rows[year][i] is the same as the previous $rows[year][i-1]. If its different, it prints out a formatted &lt; TR >.</p>

<p>Seems like a way to avoid this error would be to first check if the value of $i is zero, but I'm wondering if there is another way. Possibly in my if conditional.</p>
