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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测