2010-08-11 76 views
0

對於我正在建設的網站,我需要檢查一個位置是否有合同,這些位置可以有直接鏈接到它們的合約,或者當大型組織的一部分也有合同鏈接到該組織。在Doctrine結果中重複數組鍵

我試圖用一個DQL查詢首先檢查是否有合同直接再聯繫,如果有任何通過這個查詢的organistion鏈接:

$q = self::createQuery("l") 
     ->select('sl.sc_id, sl.type, so.sc_id, so.type, l.naam, l.loc_id, l.straat, l.telefoon, l.plaats, l.postcode, l.huisnummer, l.huisnummer_achtervoegsel, o.naam') 
     ->from('Locatie l, l.Organisatie o, l.Sc sl, o.Sc so') 
     ->orderBy('o.naam, l.naam') 
     ->execute(); 

它做什麼,我想在這麼多如,它返回一個數組與所有的數據,我需要:

array(13) { 
["loc_id"]=> string(2) "93" ["org_id"]=> string(1) "9" ["naam"]=> string(12) "test" 
["Organisatie"]=> array(4) { ["org_id"]=> string(1) "9" ["naam"]=> string(3) "test" 
["Sc"]=> array(1) { [0]=> array(6) { ["sc_id"]=> string(1) "1" ["sc_nummer"]=> NULL ["type"]=> string(6) "All-in" } } } 
["Sc"]=> array(0) { } 

}

問題是重複的[「SC」]鍵,因爲在PHP當陣列具有重合的K餘仁生,這最後關鍵覆蓋了第一個(我反正看),這使得它不可能做出那樣的檢查:

if(!empty($SC) or !empty($SC2) {} 

我似乎無法弄清楚如何使教義名的關鍵之一不同或者甚至可以合併這兩者。

我試過使用INDEXBY但改變了['SC']數組內的鍵而不是['SC']本身。

任何想法?

回答