0

I need a little bit of help, being a newb with php.

if($catname != 'used-cars' && $currentpage IS NOT 1,2,3.....100){
}

How can I write this corectly? Maybe put the numbers inside an array?

Ty

2
  • So $currentpage will be a single number? Commented May 2, 2012 at 16:08
  • Looks like $currentpage is a page id. Commented May 2, 2012 at 16:10

5 Answers 5

2

Use ! and in_array()

$array = array(1, 2, 3... , 100);

if($catname != 'used-cars' && !in_array($currentpage, $array)){

}

http://php.net/manual/en/function.in-array.php

Sign up to request clarification or add additional context in comments.

Comments

1
if($catname != 'used-cars' && !in_array($currentpage, range(1, 100))

Or:

if($catname != 'used-cars' && ($currentpage < 1 || $currentpage > 100))

1 Comment

This is a nice solution if 1, 2, 3, ... 100 was actually what he was going for... I just assumed that the data was not always necessarily a range.
0
if($catname != 'used-cars' && !in_array($currentPage, array(1, 2, 3, ..., 100)))
{}

Comments

0

Assuming you want all numbers withing the range of 1-100, you can use in_array() and range() like so:

if (($catname != "used-cars") && (!in_array($currentPage, range(1,100))) {
   //Do Stuff
}

Comments

0

Maybe something like this might work?

if($catname != 'used-cars' && $currentpage > 100)
{
    //Code here
}

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.