Hi.
On Sunday 12 April 2009, PJ wrote:
> foreach does not allow for different formatting for output...
[snip]
> But how do you get result1, result2 & result3 // with <br> at end ?
$lastIndex = count($a) - 1; // Adjust for zero-indexing.
$outputString = '';
foreach ($a as $index => $value) {
if ($index != $lastIndex) {
$outputString .= "$value, ";
} else {
$outputString = rtrim($outputString,', '); // Strip last comma.
$outputString .= " & $value<br />";
}
}
echo $outputString;
Like that? If your array is associative you can drop the $lastIndex calc
and adjust the loop to update a counter instead.
HTH
Mark
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php