array handling
|entries per row
| see demonstration of entries per rowlist entries or images with as many entries per row you specify.
perfect for an image gallery.
full source of entries per row [ line 1 - 45 ] | download entries per row
| 1 | <?php |
| 2 | // your data in an array |
| 3 | $images = array( |
| 4 | 'some', |
| 5 | 'data', |
| 6 | 'or', |
| 7 | 'images', |
| 8 | 'you', |
| 9 | 'want', |
| 10 | 'to', |
| 11 | 'show', |
| 12 | 'with', |
| 13 | 'as', |
| 14 | 'many', |
| 15 | 'entries', |
| 16 | 'per', |
| 17 | 'row', |
| 18 | 'as', |
| 19 | 'you', |
| 20 | 'specify'); |
| 21 | // how many entries per row |
| 22 | $per_row = 3; |
| 23 | echo ' |
| 24 | <table>'; |
| 25 | $count = 0; |
| 26 | for($x = 0; $x < count($images); $x++) |
| 27 | { |
| 28 | if($count == 0) |
| 29 | { |
| 30 | echo ' |
| 31 | <tr>'; |
| 32 | } |
| 33 | echo ' |
| 34 | <td>'.$images[$x].'</td>'; |
| 35 | $count++; |
| 36 | if(($count == $per_row) || ($images[$x] == end($images))) |
| 37 | { |
| 38 | echo ' |
| 39 | </tr>'; |
| 40 | $count = 0; |
| 41 | } |
| 42 | } |
| 43 | echo ' |
| 44 | </table>'; |
| 45 | ?> |
27 hits by 14 users in the last 30 minutes.