webguync Posted April 23, 2010 Share Posted April 23, 2010 Hi I currently have some code which creates a <table><tr> and <td> for each value. I only want one <table> and <tr>, but not sure how to take those elements out of the loop. Here is my code... foreach($answers as $value){ if (in_array($value, $wrong)){ $class = "wrong"; } else { $class = "correct"; } echo "<table><tr><td class=\"$class\">$value</td></tr></table>"; } ?> Link to comment https://forums.phpfreaks.com/topic/199552-taking-and-out-of-the-loop/ Share on other sites More sharing options...
JAY6390 Posted April 23, 2010 Share Posted April 23, 2010 echo '<table><tr>'; foreach($answers as $value){ if (in_array($value, $wrong)){ $class = "wrong"; } else { $class = "correct"; } echo "<td class=\"$class\">$value</td>"; } echo '</tr></table>'; Link to comment https://forums.phpfreaks.com/topic/199552-taking-and-out-of-the-loop/#findComment-1047398 Share on other sites More sharing options...
mikesta707 Posted April 23, 2010 Share Posted April 23, 2010 echo "<table><tr>" foreach($answers as $value){ if (in_array($value, $wrong)){ $class = "wrong"; } else { $class = "correct"; } echo "<td class=\"$class\">$value</td>"; } echo "</tr></table>"; edit: meh beaten before i could post, but posting anyways Link to comment https://forums.phpfreaks.com/topic/199552-taking-and-out-of-the-loop/#findComment-1047400 Share on other sites More sharing options...
JAY6390 Posted April 23, 2010 Share Posted April 23, 2010 Very close Mike Link to comment https://forums.phpfreaks.com/topic/199552-taking-and-out-of-the-loop/#findComment-1047403 Share on other sites More sharing options...
webguync Posted April 23, 2010 Author Share Posted April 23, 2010 great, thanks! Link to comment https://forums.phpfreaks.com/topic/199552-taking-and-out-of-the-loop/#findComment-1047413 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.