2011-01-05 64 views
0

另一場我有我的陣列Array ( [0] => Dusche [1] => Mobliert )如何在另一個陣列進行數據檢索從一個陣列,並顯示它作爲CakePHP的

而且我有第二個陣列至極組成,看起來像這樣:

[0] => Array 
    (
     [id] => 1002 
     [attribute_id] => 65 
     [value_id] => 26815 
     [name] => Garten/-mitbenutzung 
     [order] => 0 
    ) 

[1] => Array 
    (
     [id] => 1003 
     [attribute_id] => 65 
     [value_id] => 26811 
     [name] => Etagenheizung 
     [order] => 1 
    ) 

[2] => Array 
    (
     [id] => 1004 
     [attribute_id] => 65 
     [value_id] => 26829 
     [name] => Balkon/Terrasse 
     [order] => 2 

如何用第一個數組中的值搜索第二個數組,並從具有相同名稱的元素中檢索attribute_id?

回答

1

PHP方式:

filteredArray = array(); 
foreach ($secondArray as $type) { 
    if (in_array($type['name'], $firstArray)) { 
     $filteredArray[] = $type['attribute_id']; 
    } 
} 

蛋糕Set方式,沿着線的東西:

$filteredArray = array(); 
foreach ($firstArray as $keyword) { 
    $filteredArray = array_merge($filteredArray, Set::extract("/.[name=$keyword]/attribute_id", $secondArray)); 
}