TheNix Posted March 5, 2009 Share Posted March 5, 2009 I know to print an array i can do foreach($names as $value){ echo $value; } But what if I just want to print the 10, then break and print the next 10, till i run out? Link to comment https://forums.phpfreaks.com/topic/148154-print-part-of-an-array/ Share on other sites More sharing options...
genericnumber1 Posted March 5, 2009 Share Posted March 5, 2009 I'm not sure what you mean, why would you want to print 10, break and then print 10 when you could just print 20 to begin with? Link to comment https://forums.phpfreaks.com/topic/148154-print-part-of-an-array/#findComment-777708 Share on other sites More sharing options...
TheNix Posted March 5, 2009 Author Share Posted March 5, 2009 Well I have an array of names that have been randomized and I want to place a number of them, up to 10 at a table then place the same at the next table and so on till I'm out of people. I was just trying to make a simple example. Link to comment https://forums.phpfreaks.com/topic/148154-print-part-of-an-array/#findComment-777712 Share on other sites More sharing options...
Psycho Posted March 5, 2009 Share Posted March 5, 2009 It would be much easier if you gave an exampe of the code you want to use to display these in. You say you wnat 10 names in each table, but did you mean 10 names in each row of a table? Anyway here is a quick example of how to do it with separate tables (not tested): <?php $count = 1; foreach ($names as $name) { if ($count==1) { echo "<table><tr>"; } echo "<td>$name</td>"; $count++; if ($count>10) { echo "</tr></table>"; $count = 1; } } if ($count!=1) { echo "</tr></table>"; } ?> Link to comment https://forums.phpfreaks.com/topic/148154-print-part-of-an-array/#findComment-777726 Share on other sites More sharing options...
TheNix Posted March 5, 2009 Author Share Posted March 5, 2009 Thank you very much Link to comment https://forums.phpfreaks.com/topic/148154-print-part-of-an-array/#findComment-777728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.