How to simplify if conditions?
<p>How can I simplify if conditions, because per each condition I make a new if/elseif and its a lot of code, this is what I have:</p>

<pre><code>$chapters = array('1:data1', '2:data2', '4:datax', '3:datag');
sort($chapters);
$screenshots = array('1:screen1', '2:screen2', '3:screen3', '4:go4');
$chapterCount = count($chapters);
$chapterItems = 0;

foreach ($screenshots as $key =&gt; $screenshot) {
    $screenshotInfo = explode(':', $screenshot);
    $screen[$screenshotInfo[0]] = $screenshotInfo[1];
}

foreach ($chapters as $chapter) {
    $chapterInfo = explode(':', $chapter);
    $chapterNumber = current($chapterInfo);
    // If is the first chapter
    if ($chapterNumber == 1) {
        echo '&lt;li&gt;'.$chapterInfo[0].'&lt;/li&gt;';
        // If have only one chapter
        if ($chapterItems+1 == $chapterCount) {
        echo '&lt;li&gt;'.$screen[$chapterNumber].'&lt;/li&gt;';
        }
    }
    // If is a new chapter
    elseif ($currentNumber != $chapterNumber) {
        echo '&lt;li&gt;'.$screen[$chapterNumber-1].'&lt;/li&gt;';
        echo '&lt;li&gt;'.$chapterInfo[0].'&lt;/li&gt;';
        // If is new and last chapter
        if ($chapterItems+1 == $chapterCount) {
        echo '&lt;li&gt;'.$screen[$chapterNumber].'&lt;/li&gt;';
        }
    }
    // If is the last chapter
    elseif ($chapterItems+1 == $chapterCount) {
        echo '&lt;li&gt;'.$chapterInfo[0].'&lt;/li&gt;';
        echo '&lt;li&gt;'.$screen[$chapterNumber].'&lt;/li&gt;';
    }
    else {
        echo '&lt;li&gt;'.$chapterInfo[0].'&lt;/li&gt;';
    }

    $currentNumber = $chapterNumber;
    $chapterItems++;
}
</code></pre>

<p>That code works perfect on my tests but I'm sure it have a lot of unneeded code.</p>
