B
B
BiTor2018-03-01 19:16:37
PHP
BiTor, 2018-03-01 19:16:37

How to display data in a php loop in a certain order?

Hello, tell me who can... There is an array like $arr=[1,2,3,4,5,6,7, etc...
] elements in the $arr array, which is actually not a problem ..
The problem is this)
How to display data from the array in the first row of the table in this order (1 array element, 2nd, empty cells) and the second line (1 array element, empty cell , 3rd element, empty cells) in the third star (1 element of the array, empty cell, empty cell, 4th element of the array) and so on until the last element of the array.
5a98267eef04c824819688.png
Please provide an example or a link on the topic.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bears, 2018-03-01
@BiTor

Try like this:

<?php $arr = range(1, 50); ?>

<table border="1">
    <?php for ($k = 0; $k < count($arr); $k++): ?> 
        <tr>
            <?php for ($i = 0; $i < count($arr); $i++): ?>
                <td><?php echo ($i - 1 === $k || $i === 0) ? '+' : '' ?></td>
            <?php endfor; ?>
        </tr>
    <?php endfor; ?>
</table>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question