It is worth the trouble to learn arrays...
// Set a counter and reset our output string $xtopics
$xtopics = '';
$i = 0;
// Walk through $topics from 0 to the max number of topics
foreach ($topics as $topic) {
if($topic)
$xtopics .= "Topic$i: $topic<br>\n";
$i += 1;
}
// Strip off last line break if there is something to strip off
if($xtopics != "")
$xtopics = substr($xtopics,-5);
How do you use arrays? Here...
// Fill first 4 elements of $topics
$topics = array('this is my first topic',
'this is my second topic',
'this is my thrid topic',
'this is my fourth topic'); // first four topics
// Change element 3 of topics
$topics[3] = 'this is my third topic'); // change third topic
// Add a fifth element to topics
$topics[count($topics)+1] = 'this is my fifth topic'); // set fifth topic
Arrays allow you to dynamically add and remove topics instead of hard-coding a certain number of topics.