Combining Three Arrays in foreach loop in PHP

后端 未结 2 1910
梦毁少年i
梦毁少年i 2021-01-27 09:57

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 array

2条回答
  •  难免孤独
    2021-01-27 10:12

    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
    "; }

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

提交回复
热议问题