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";
}

3 Answers 3

4
in_array($_REQUEST['Itemid'], $productId)
Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

Your Answer

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.