2012-10-18 46 views
-1

我有這樣連接兩個指標值在每個

$rr=array(); 

foreach($relations as $key=>$type){ 
    $rr[$relationType->U2U_Related_USR_ID]=$type[$k]->MSTT_Name.'/'.$type[$k+1]->MSTT_Name; 
    $k++; 
} 

上午只得到第一指標值的循環。如何爲每個連接兩個索引值。

+0

目前尚不清楚哪些指標應該是什麼值應爲。請舉例說明索引中應連接的內容。 –

+0

**請審覈並批准答案。** – Florent

回答

0

增加!

$rr = array(); 

for ($i = 0, $n = count($type); $i < $n; $i += 2) { 
    $t1 = $type[$i]; 
    $t2 = $type[$i + 1]; 
    $rr[$relationType->U2U_Related_USR_ID] = $t1->MSTT_Name.'/'.$t2->MSTT_Name; 
} 

注:$type的長度應爲偶數!

0

你可以用兩對夫婦鍵/值你的工作循環內是這樣的:

foreach($relations as $key=>$type){ 

    list($odd_key, $odd_value) = each($relations); 

    //... your code here 

    // This work with a step by 2 elements. If you need step by 1, 
    // add the following line at the end of the loop : 

    //prev($relations) 
}