我正在显示所有10个手指的手指图像,每个手指显示3个图像,所以手指总数为30。我在表中使用动态循环打印此图像,我希望每个手指显示一个输入框,所以如果有是两个手指,则应显示两个输入框。
我已经解码了对象数组并使用foreach函数进行打印,但是当我尝试显示输入框时,它仅显示一个输入框,但是我希望根据数组值添加更多输入框。
这是我的数组:
Array ( [0] => stdClass Object ( [code] => 0 [message] => Success [bio_id] => 1 [ref_id] => 2 [hand] => 1 [fin] => 1 [poz] => 1 ) [1] => stdClass Object ( [code] => 0 [message] => Success [bio_id] => 1 [ref_id] => 2 [hand] => 1 [fin] => 1 [poz] => 2 ) [2] => stdClass Object ( [code] => 0 [message] => Success [bio_id] => 1 [ref_id] => 2 [hand] => 1 [fin] => 1 [poz] => 3 ) [3] => stdClass Object ( [code] => 0 [message] => Success [bio_id] => 1 [ref_id] => 2 [hand] => 1 [fin] => 2 [poz] => 1 ) [4] => stdClass Object ( [code] => 0 [message] => Success [bio_id] => 1 [ref_id] => 2 [hand] => 1 [fin] => 2 [poz] => 2 ) [5] => stdClass Object ( [code] => 0 [message] => Success [bio_id] => 1 [ref_id] => 2 [hand] => 1 [fin] => 2 [poz] => 3 ) )
这是我的代码:
$finger = json_decode($blob->getallbiofile());
//print_r($finger);
$i = 0;
foreach($finger as $fing) {
if($fing->code == '0'){
$i++;
?>
<tr>
<td class="">
<?php echo $finhelp->fingurevalue("hand", $fing->hand); ?> -
<?php echo $finhelp->fingurevalue("fin", $fing->fin); ?> -
<?php echo $finhelp->fingurevalue("poz", $fing->poz); ?></td>
<td class="center">
<a href="showfinger?id=<?=$fing->bio_id?>" target="_blank">
<img src="images/fingerprint.png" class="img-circle img-responsive reportfingerimage"></a>
</td>
<?php
if($i == $fing->fin) { ?>
<td class="" rowspan="3">
<div class="col-xs-2">
<input type="hidden" name="hand[]" value="<?=$fing->hand?>">
<input type="hidden" name="finger[]" value="<?=$fing->fin?>">
<input class="form-control fininput" id="ex1" name="finger_value[]" type="text" value="">
</div>
</td>
<?php
continue;
}
?>
</tr>
<?php
}
}
?>
输出我越来越喜欢图像链接 (“ https://eruditioninformatics.cf/imagelinks/WebAdminPanel.png”),但我希望另外一根手指输入框。
答案 0 :(得分:0)
我的解决方案是每次检查foreach循环以获取手指值并将其存储到数组中。检查值是否与foreach循环值不同,然后打印一次输入框,并将另一个手指值保存到数组中。现在最终的代码是:
$i = 0;
foreach($finger as $fing) {
$i++;
使用
$finarray = array();
foreach($finger as $fing) {
和:
if($i == $fing->fin) {
具有:
if(!in_array($fing->fin, $finarray, true)) {
$finarray[] = $fing->fin;
现在我正在为每个手指输入框。