2012-07-03 60 views
2

我是一名PHP初學者,我想要做以下事情:php數組數組

我想將一個數組數組與一個itemid進行比較。目前,我的代碼只在我聲明要檢查的數組的哪個位置(productId)時有效。我如何檢查productId來測試數組的全部內容?

$productId = array(146,147,148,149,150,151,152,153,154,155,158,159,160,161,162, 
        163,113,116,117,118,114,119,120,121,115,121,122,123,124); 

if(($_REQUEST['view'] == 'article') && ($_REQUEST['Itemid'] == $productId[0])) { 
    $setCol = 1; 
    $setId = "main-noleft"; 
} else { 
    $setCol = null; 
    $setId = "main"; 
} 

回答

4
in_array($_REQUEST['Itemid'], $productId) 
+0

優秀謝謝 – Rob

0
you can also use this 
array_search($_REQUEST['Itemid'], $productId) 

array_search 搜索數組給定值,並返回相應的鍵,如果成功
array_search