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";
}
john_science
6,5976 gold badges45 silver badges62 bronze badges
3 Answers 3
in_array($_REQUEST['Itemid'], $productId)
answered Jul 3, 2012 at 11:11
Vladimir Kadalashvili
7472 gold badges5 silver badges19 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Use the in_array function: http://php.net/in_array
answered Jul 3, 2012 at 11:11
J. Bruni
20.5k13 gold badges80 silver badges93 bronze badges
Comments
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
Comments
lang-php