简体   繁体   中英

php numeric array

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";
}
in_array($_REQUEST['Itemid'], $productId)

使用in_array函数: http : //php.net/in_array

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

array_search Searches the array for a given value and returns the corresponding key if successful
array_search

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM