[英]How to loop tr, td of a table based on letter instead of number
Currently I have a table and is currently coded as: 目前,我有一张桌子,当前编码为:
$min_hor = $min_ver = 1;
$max_hor = $max_ver = 3;
?>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
.table{
margin: 0 auto;
}
</style>
<div class="text-center">
<table class="table" style="width:70%">
<thead>
<tr>
<th></th>
<?php for($j=$min_hor; $j<=$max_hor; $j++){ ?>
<th><?php echo str_pad($j, 2, "0", STR_PAD_LEFT); ?></th>
<?php } ?>
</tr>
</thead>
<tbody>
<?php for($i=$min_ver;$i<=$max_ver;$i++){ ?>
<tr>
<th><?php echo $i; ?></th>
<?php for($j=$min_hor; $j<=$max_hor; $j++){ ?>
<td><?php echo $i.'-'.str_pad($j, 2, "0", STR_PAD_LEFT) ?></td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
This display table as shown in attached screenshot. 该显示表如所附屏幕快照所示。
Now, I have one additional array as $letter_array = array('A','B');
现在,我还有一个数组,如
$letter_array = array('A','B');
This array is could be bigger than this one and could be upto D,E,F,...
此数组可能大于此数组,并且可能高达
D,E,F,...
Now, I need to include this A,B
into the table header something like as shown in screenshot. 现在,我需要将此
A,B
包括在表标题中,如屏幕截图所示。
This is where I became helpless. 这就是我变得无助的地方。 I couldn't find how could I loop this.
我找不到如何循环播放此内容。 Although, to make things easier, I have included codepen link of html code.
虽然,为了使事情变得容易,我包括了html代码的codepen链接。
How about we keep headers in 2 different Arrays and then perform a loop.following is the pseudocode which i think will work. 我们如何将标头保留在2个不同的数组中,然后执行循环。以下是我认为可以使用的伪代码。
string a[16]={'01','02','03',......,'B'};
string b[17]={'1','2','3',....,'B'};
<table class="table" style="width:70%">
<thead>
<tr>
<th></th>
foreach(var item in a)
{
<th>{{item}}</th>
}
</tr>
</thead>
<tbody>
foreach(var item2 in b)
{
<tr>
<td>{{item2}}</td>
foreach(var item in a)
{
<td>{{item2}}_{{item}}</td>
}
</tr>
}
</tbody>
</table>
Now, before generating table we need elements at array A and B. to generate the array ie a and b we can do following : 现在,在生成表之前,我们需要数组A和B的元素。要生成数组即a和b,我们可以执行以下操作:
int min_hor=1;
int max_hor=3;
var a_output=[];
var a_inputLetter=['A','B'];
//first for number only.here let us create a string and push to a_output.
for(int i=min_hor,i<=max_hor;i++)
{
a_output.Add('0'+i);
}
//second let us use Number Letter Combination
foreach(var item in a_inputLetter)
{
for(int i=min_hor;i<=max_hor;i++)
{
a_output.Add('0'+{{i}}_{{item}});
}
}
//third for letter number combination
foreach(var item in a_inputLetter)
{
for(int i=min_hor;i<=max_hor;i++)
{
a_output.Add({{item}}_{{i}});
}
}
//and finally for letter_only
foreach(var item in a_inputLetter)
{
a_output.Add({{item}});
}
//similarly do for Array B as well to generate the second array.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.