2016-09-01 86 views
-1

我想在foreach循環中再添加一個數組。 下面是代碼:foreach中的兩個數組

$products = array(); 

$products = get_cat_images(); 

$name = array(); 

$name = get_cat_name(); 

foreach(array_chunk($products, 3) as $arr_images) { 
    echo "<div class = \"row\">"; 
    foreach($arr_images as $detail_image) { 
     echo "  
     <div class=\"col-sm-4 col-md-4\"> 
      <div class=\"service\"> <!-- Service #1 --> 
      <a href=\"service/civil-architecture.html\"> 
       <img src=\"http://elektroteni.ru/".$detail_image."\" alt=\"\" class=\"img-responsive\"> 
      </a> 
      <a href=\"service/civil-architecture.html\"><h4>".$name."</h4></a> 
      <p>description of the product</p> 
      <a class=\"read-more\" href=\"service/civil-architecture.html\">Read More <span class=\"fa fa-chevron-circle-right\"></span></a> 
      </div> 
     </div>  
     "; 
    } 
    echo "</div>"; 
} 

所以我想在循環正常顯示$name陣列。 有幫助嗎?

+0

告訴我們您的數組爲好。 – Noman

+0

顯示此問題的表格。 –

+0

該數組中的內容向我們展示了它的結構 –

回答

-1

試試這個:

$i=0; 
foreach(array_chunk($products, 3) as $arr_images) { 
       echo "<div class = \"row\">"; 
        foreach($arr_images as $detail_image) { 
         echo " 

          <div class=\"col-sm-4 col-md-4\"> 
           <div class=\"service\"> <!-- Service #1 --> 
            <a href=\"service/civil-architecture.html\"> 
             <img src=\"http://elektroteni.ru/".$detail_image."\" alt=\"\" class=\"img-responsive\"> 
            </a> 
            <a href=\"service/civil-architecture.html\"><h4>".$name[$i]."</h4></a> 
            <p>description of the product</p> 
            <a class=\"read-more\" href=\"service/civil-architecture.html\">Read More <span class=\"fa fa-chevron-circle-right\"></span></a> 
           </div> 
          </div> 

         "; 
$i++; 
        } 
       echo "</div>"; 

      } 
+0

非常感謝!它爲我工作 –

+1

@AibolOrazbekov:如果答案是有用的比接受答案這將有助於其他人 – devpro