I have a question, I would like to count how many times a td is printed in a table, this td is printed through a foreach in php and calls a table with respect to its fields.
foreach($materias_cursar as $index => $materia): ?>
<tr>
<td><?= $materia['component'] ?></td>
<td><?= $materia['name_subject'] ?></td>
<td><?= $materia['code_subject'] ?></td>
<td><?= $materia['credits'] ?></td>
I already tried with for but it doesn't tell me exactly how many times it prints the td, really I only tried with php not and tried with javascript
I am not very knowledgeable about PHP, but the logic to solve your problem would be a counter for the
TD
, and since we know that eachTD
prints 4TR
, in the end, after counting all theTR
, we multiply by 4, since it is the numberTD
of print byTR
. It would be something like this: