displaying multiple lines of a file, never repeating
问题 i need to, for every ten lines, echo them in a div. example: <div class='return-ed' id='1'> line 1 line 2 ... line 9 line 10 </div> <!-- next group of lines --> <div class='return-ed' id='2'> line 11 line 12 ... line 19 line 20 </div> does anyone know a way to do this? array is from file(), so its lines from a file. 回答1: This should work: $blocks = array_chunk(file('path/to/file'), 10); foreach($blocks as $number => $block) { printf('<div id="%d">%s</div>', $number+1, implode('<br/>', $block)