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";
}
john_science
6,5976 gold badges45 silver badges62 bronze badges
asked Jul 3, 2012 at 11:09

3 Answers 3

4
in_array($_REQUEST['Itemid'], $productId)
answered Jul 3, 2012 at 11:11
Sign up to request clarification or add additional context in comments.

Comments

1

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

answered Jul 3, 2012 at 11:11

Comments

0
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

answered Jul 3, 2012 at 11:18

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.