tags:

views:

67

answers:

2

Heya,

I have a loop which generates a table code for a specific number of times. What I'm having problems with is to echo a variable inside the loop.

The loop runs 10 times, and there are 10 text messages sent to the page, so my problem is how do I get each of the looped tables to echo one of the text messages each time?

A: 

Okay, with such limited information, I'm going to take a stab at answering.

Presuming you have an array of 'messages', for example:

$messages = array('My message', 'Hello Dave', 'Beans are delicious');

If you wanted to loop over (specifically using a for loop) and output the corresponding message, you could do:

for ($i = 0; $i < count($messages); $i++) {
    echo $messages[$i];
}

If that's not what you wanted to know, you're going to have to clarify your question.

James Burgess
A: 
<table>
foreach ($messages as $message) {
    echo '<tr><td>' . $message . '</td></tr>';
}
</table>
Cory House