for() is a very simple loop structure:
for(expr1; expr2; expr3)
statement;
PHP will execute expr1 first. Then it will check expr2. If expr2 evaluates to true, it will execute statement. After executing the statement, it will run expr3. Then it will check expr2 again, and if it still returns true, it will execute statement again and so on. Example:
for($i = 1; $i <= 10; $i++) // Set counter to 1, check if it is less than 10, increment it at the end of the loop
echo $i." "; // Prints 1 2 3 4 5 6 7 8 9 10
Heredoc-style strings is just an easy way to write a string without escaping sequences all the time. Everything between <<<EOD and EOD; will be considered a string.
Since we're going to be checking if the list item is the first one, though, I won't use heredoc, because it's easier to use a normal string in this case.
// Create the <ul> list
echo " <ul class=\"ui-tabs-nav\">";
for($i = 0; $i < count($slider); $i++)
echo " <li class=\"ui-tabs-nav-item".($i == 0 ? " ui-tabs-selected" : "")."\" id=\"nav-fragment-$i\"><a href=\"#fragment-$i\"><img src=\"".$slider[$i]["image"]."\" alt=\"\" /><span>".$slider[$i]["subject"]."</span></a></li>\r\n";
// End list
echo " </ul>";
for($i = 0; $i < count($slider); $i++)
echo " <div id=\"fragment-$i\" class=\"ui-tabs-panel".($i != 0 ? " ui-tabs-hide" : "")."\">
<img src=\"".$slider[$i]["image"]."\" alt=\"\" />
<div class=\"info\">
<h2><a href=\"#\">".$slider[$i]["subject"]."</a></h2>
<p>".$slider[$i]["body"]".… <a href=\"".$slider[$i]["id"]."\">read more</a></p>
</div>\r\n";
As a side note, if you don't know, I used a shorthand expression in there that some programming languages implement:
(expr ? statement1 : statement2)
If expr evaluates to true, statement1 will be executed; otherwise, statement2 will be executed. It's just a little cleaner and shorter than an if() conditional.