du0173 2016-03-24 05:01
浏览 55
已采纳

我怎样才能在php中取消for和foreach循环值

My html code is:

<table cellpadding="0" cellspacing="0" border="1" class="pro_code_table">
    <tr>
        <th colspan="12" class="pro_code_lable_with_data">Product Code Detailes</th>
    </tr>
    <tr>
        <td class="table_val_data">Title</td>
    @foreach($x as $k_x => $v_x)
        <td class="table_val_data">{{ $v_x }}</td>  
    @endforeach
    </tr>
    <tr>
    @foreach ($y as $k_y => $v_y) 
        <td class="table_val_data">{{ $v_y }}</td>
    <?php $pro_code_count=count($pro_code);
    //print_r($pro_code);
    ?>
    @for($r = 1; $r <=sizeof($x); $r++)
        <td>
        <?php $i=1; ?>
        @foreach($pro_code as $key=>$val)
        @if($i % 2 != 0)
          <input type="text" name="pro_code[]" value="{{ $val }}">
        @else
          <input type="text" name="pro_code[]" value="{{ $val }}">
        @endif
        @endforeach
        <?php 
        $i++;
        ?>
        </td>
        @endfor
    </tr>
    @endforeach
</table>

In that i can loop data inside table, the X and Y axis looped correctly, but inside an <td> datas are looped more then one time,

nw how can i stop the looping process

my o\p is looking like below

enter image description here

i want data like an below like that

enter image description here

  • 写回答

1条回答 默认 最新

  • drexlz0623 2016-03-26 06:59
    关注
    <table cellpadding="0" cellspacing="0" border="1" class="pro_code_table">
    <tr>
    <th colspan="12" class="pro_code_lable_with_data">Product Code Detailes</th>
    </tr>
    <tr>
    <td class="table_val_data">Title</td>
    @foreach($x as $k_x => $v_x)
    <td class="table_val_data">{{ $v_x }}</td>
    @endforeach            
    </tr>
    
    <tr>
    @foreach($y as $k_y_t=> $v_y_t)
    <td class="table_val_data">{{ $v_y_t }}</td>
    
    @foreach($y as $k_y=> $v_y)
        @foreach($x as $k_x => $v_x)
        @if($k_y_t==$k_y)
            <td class="table_val_data">
        @foreach($pro_code as $k_pro_code=> $v_pro_code)            
        <?php
        if($k_x.'-'.$k_y==$k_pro_code){
            echo '<input type="text" name="value" value="'.$v_pro_code.'">';
        }                   
        ?>
        @endforeach             
        </td>
        @endif    
        @endforeach 
    @endforeach 
    </tr>
    
    @endforeach
    </table>
    
    $x: {"3":"bule","4":"green"}
    $y: {"5":"cotten","6":"polyester"}
    $pro_code_in_edit: {"3-5":"12","4-5":"23","3-6":"56","4-6":"89"}
    

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line