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.
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.)
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?
<?php
$directory = 'includes/pages';
$dirIT = new DirectoryIterator($directory);
try {
// Pull in HTML files from directory
foreach ( $dirIT as $key => $item ) {
if ($item->isFile()) {
if ( $key == '0')
{
echo "<div class=\"one-third column alpha\">";
$path = $directory . "/" . $item;
include $path;
echo "</div>";
}
elseif ($key == count ( dirIT ) - '1' )
{
echo "<div class=\"one-third column omega\">";
$path = $directory . "/" . $item;
include $path;
echo"</div>";
}
else
{
echo "<div class=\"one-third column\">";
$path = $directory . "/" . $item;
include $path;
echo "</div>";
}
}
}
}
catch(Exception $e) {
echo 'There are no pages to display.<br />';
}
?>
isfine as long as he's not using === or !==.