PHP use glob() to feed array into foreach loop with IF Then Logic
<p>Right off the bat I know there are already alot of threads on here about using Glob() to feed a foreach loop.  I've read every one I can find and I still have difficulty so I though I would post my code here in the event I am missing something.</p>

<p>My goal: use a foreach loop to wrap HTML pages in some markup and display them on my page.  I could have just written the HTML right into my page, but I anticipate alot changes and additions in the next couple of weeks and Im worried about overlapping versions (cant use version control here.)</p>

<p>So far I have this script pulling in the pages and displaying them but IF logic is not triggering.  What am I doing wrong here?</p>

<pre><code>&lt;?php

        $directory = 'includes/pages';
        $dirIT = new DirectoryIterator($directory);
        try {        
            // Pull in HTML files from directory    

            foreach ( $dirIT as $key =&gt; $item ) {           
                if ($item-&gt;isFile()) {

                    if ( $key == '0')
                    {
                        echo "&lt;div class=\"one-third column alpha\"&gt;";
                        $path = $directory . "/" . $item;
                        include $path;
                        echo "&lt;/div&gt;";
                    }

                    elseif ($key == count ( dirIT ) - '1' )
                    {
                        echo "&lt;div class=\"one-third column omega\"&gt;";
                        $path = $directory . "/" . $item;
                        include $path;
                        echo"&lt;/div&gt;";
                    }

                    else
                    {
                    echo "&lt;div class=\"one-third column\"&gt;";
                    $path = $directory . "/" . $item;   
                    include $path;  
                    echo "&lt;/div&gt;";
                    }
                }
            }   
        }   
        catch(Exception $e) {
            echo 'There are no pages to display.&lt;br /&gt;';    
        }
    ?&gt;
</code></pre>
