dongling3243 2014-04-22 18:40
浏览 108

在PHP中的foreach循环中组合三个数组

I know how to combine two arrays in foreach loop using array_combine() function of PHP

But I have three arrays and I want to loop through all of three arrays at a time.

$get_id=$data->get_id;
$get_product=$data->get_product;
$get_comment=$data->get_comment;

foreach (array_combine($get_id, $get_product) as $id => $product) {
    echo "$id - $product<br/>";

}

I want to iterate $get_comment array too in this loop.

Thanks

  • 写回答

2条回答 默认 最新

  • dongsisui7562 2014-04-22 18:58
    关注

    Combine the arrays before the foreach loop

        $comment_array = array_combine($get_id, $get_comment);
        $product_array = array_combine($get_id, $get_product);
        foreach ($product_array as $id => $product) {
          $comment = $comment_array[$id];
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度