後更新我有兩個大的數組:的foreach計數沒有得到array_splice
$a = array('a1','a2','a3','a4'); // and so on
$b = array('b1'=>'a1', 'b2'=>'a3', 'b3'=>'a1'); //
我希望得到以下結果:
$a = array('a1'=>array('b1', 'b3'), 'a2'=>array(), 'a3'=>array('b2'));
我可能只是這樣做:
foreach($a as $aa){
foreach($b as $bb){
// check with if then add to a
}
}
但它會變得非常大,數量更大。
因此,我想到如果刪除每個'b'元素後被添加到$a
下一個循環會更小,我會切斷資源。
但是拼接環形陣列時,該指數似乎並沒有得到更新,而實際上,它是由1
砍下我怎樣才能使這項工作的下一個循環沒有考慮到,另外,是否有更好的方法將數組的項匹配到另一個數組的適當索引中?
編輯:
怎麼會變成這樣做如果兩個$a
和$b
的結構爲:
$a[0]['Word']['id']=1;
$a[0]['Word']['sentence_id']=2;
$a[0]['Word']['word_string']='someWord';
$b[0]['Word']['id']=3;
$b[0]['Word']['sentence_id']=4;
$b[0]['Word']['word_string']='someWord';
// And i would like to list `b` like so:
$a[0]['list_of_bs']=array(b[0], b[1]);
//So that i can get:
echo $a[0]['list_of_bs']['Word']['id'];
// and to get result 3
,我想它是$a[0][Word][list_of_b]=array(b1,b2,b3)
並且每個b
的的有它自己的數據在關聯數組中。
是什麼'$了'和'$ B' – Baba 2012-04-16 10:25:05
的關係之間的關係是每個'$ B'元素具有適當的'$了'元素的索引,需要被添加到它。 – mgPePe 2012-04-16 10:34:35
好的...我現在明白了..認爲我有一個自解決方案 – Baba 2012-04-16 10:47:41