2

I am a PHP beginner and I want to do the following:

I want to compare an array of numbers to an itemid. Currently, my code only works if I state which position of the array to check (productId). How can I check productId to test the whole contents of the array?

$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

3 に答える 3

4
in_array($_REQUEST['Itemid'], $productId)
于 2012-07-03T11:11:45.890 に答える
1

Use the in_array function: http://php.net/in_array

于 2012-07-03T11:11:37.590 に答える
0
you can also use this
array_search( $_REQUEST['Itemid'], $productId )

array_search指定された値の配列を検索し、成功した場合は対応するキーを返します
array_search

于 2012-07-03T11:18:33.483 に答える