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

Hello, tell me who can... There is an array of type $arr=[1,2,3,4,5,6,7, etc....]
In a loop I need to output an html table, the number of cells in the row equal to the number of elements in the array $arr which in fact is not a problem..
Here is the problem)
How do I output the first line of the table data from the array in that order (1st element of the array , the 2nd, empty cells) and second row (1, array element, empty cell, 3rd element, empty cells) in the third stark (1 array element,empty cell,empty cell, 4 element of the array), and so on until the last element of the array.


Please tell me an example or link on the topic.
June 7th 19 at 14:57
1 answer
June 7th 19 at 14:59
Try this:
<?php $arr = range(1, 50); ?>

<table border="1">
 <?php for ($k = 0; $k < count($arr); $k++): ?> 
 <?php for ($i = 0; $i < count($arr); $i++): ?>
 <td><?php echo ($i - 1 === $k || $i === 0) ? '+' : "?></td>
 <?php endfor; ?>
 <?php endfor; ?>
Thank you! Very helpful! - nikita.Stracke commented on June 7th 19 at 15:02

Find more questions by tags PHP