在PHP的foreach循环中合并三个数组 [英] Combining Three Arrays in foreach loop in PHP

查看:59
本文介绍了在PHP的foreach循环中合并三个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用PHP的 array_combine()函数在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/>";

}

我也想在此循环中迭代 $ get_comment 数组.

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

谢谢

推荐答案

我认为这可能是您想要的:

I think this might be what you are looking for:

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

foreach($get_id as $i => $id){
    $product = $get_product[$i];
    $comment = $get_comment[$i];
    echo "$id , $product, $comment<br/>";
}

此解决方案假定$ get_id,$ get_product和$ get_comment数组都以相同的方式建立索引.

This solution assumes the $get_id, $get_product, and $get_comment arrays are all indexed the same way.

这篇关于在PHP的foreach循环中合并三个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆