If INT equals 3,5,8,10,13,15 (etc)

TJE

I want to have an if statement in PHP to calculate if an INT equals only certain numbers. The pattern would go like: 3, 5, 8, 10, 13, 15, 18, 20 etc. It adds 3, then 2, repeating. The pattern is consistent with the last digit (3,5,8,0), but I don't want to include the first 0.

I could do it this way, but it could go on forever...

if($int == 3 || $int == 5 || $int == 8 || $int == 10 ....)
{
    //do stuff
}

This way also does multiples of 3...

if ($int % 3 == 0)
{
    //do stuff
}

But doesn't do the pattern I want. What's the right way of doing this?

Rik

You can do it like this.

Get the remainder of the division by 10 and then check for 0, 3, 5 or 8.

if ($int > 0) {
  $int = $int % 10;
  if ($int == 0 || $int == 3 || $int == 5 || $int == 8)
  {
      //do stuff
  }
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

INT가 3,5,8,10,13,15 (등)와 같으면

분류에서Dev

int plus plus 및 int plus equals 1의 차이

분류에서Dev

Bad line 13 in /etc/fstab

분류에서Dev

What is the difference between “int *a = new int” and “int *a = new int [5]"?

분류에서Dev

원시 유형 int에서 equals (String)를 호출 할 수 없습니다.

분류에서Dev

BigInteger 및 int에 equals를 사용할 수없는 이유는 무엇입니까?

분류에서Dev

Issue with .equals()

분류에서Dev

Windows 10에서. \ etc \ hosts 파일 편집

분류에서Dev

SQL Server의 Int 10

분류에서Dev

array <int, 5> b; 및 int b [5];

분류에서Dev

Junit of equals 방법

분류에서Dev

equals () 재정의

분류에서Dev

C # this.Equals (typeof (...));

분류에서Dev

Hashcode & equals implementation

분류에서Dev

== 및 .equals () in Java

분류에서Dev

Primitive double equals to NaN

분류에서Dev

자바, JTextField .equals

분류에서Dev

Advantages and disadvantages between int vs int_fast8_t

분류에서Dev

Equals를 사용하여 Enum과 const int를 비교할 때 컴파일 오류가 발생하지 않았습니다.

분류에서Dev

(가) equals 메소드 된 invoke 별개의 자바 (8) ()하지 않습니다

분류에서Dev

display (15) 결과 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24

분류에서Dev

) (Objects.equals와 .equals ()를 교체

분류에서Dev

자바 : toString (). equals () 대 equals () 사용

분류에서Dev

Equals () 대 정적 문자열 .Equals ()

분류에서Dev

invalid literal for int() with base 10: - foreignkey

분류에서Dev

What are the benefits of "String".equals(otherString)

분류에서Dev

Integer equals 0 instead of 1

분류에서Dev

NSPredicate issue with greater than equals

분류에서Dev

Comparing Dates in java using equals

Related 관련 기사

뜨겁다태그

보관