What is the best way to make that construction, i have many record with people names, and i need to put them all to 3 strips column, beetween each column huge space, and all names can be arbitrary length, for example
|Bob| |Jonh| |Victor|
|Sergej| |Kennedi| |Mark|
|Antuan| |Kristina| |Cryst|
I need to put them all to that colums in loop automaticaly, and one after the other,
|1| |2| |3|
|4| |5| |6|
|7| |8| |9|
Maybe somebody can advice me how it will be better to do, now i create 3 <ul>
and in each ul
i have some <li>
, but that way will display my record one under the other. And if i use ul i need to get count all record, divide it to 3, and then put in each ul some record, maybe there is better way ?
As @Fabien pointed out, if its tabular data, then you can format it inside a table and use array_chunk()
to group them by three's. Consider this example:
<?php
$names = array(
'Bob',
'John',
'Victor',
'Sergej',
'Kennedi',
'Mark',
'Antuan',
'Kristina',
'Cryst',
);
$names = array_chunk($names, 3); // group them by three's
?>
<table border="0" cellpadding="10">
<?php foreach($names as $key => $value): ?>
<tr>
<?php foreach($value as $index => $element): ?>
<td><?php echo $element; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>