PHP - 如何检查条件是否在3 5 7 9之内等等

i am trying to check condition by matching 3 or 5 or 7 or 9 so on...

i want something like this but below code is not proper way to do as there are thousands of condition by adding 2.

      /// start from 3
     if ($a==3){
              $b=11;
              }
    if ($a==5){
              $b=15;
              }
    if ($a==7){
              $b=19;
              }

and so on..

Thanks for your help.

I'm guessing the relationship between $a and $b, such that:

if($a >= 3 && $a % 2 != 0){
   $b = 2 * $a + 5;
}

Looks like you want a formula instead.

How about...

if ($a >= 3 && $a % 2 == 1) { // check that $a is at least 3 and is odd
    $b = ($a * 2) + 5; // this seems to work on your examples, clarify if it's wrong
}

Create an array which contains the numbers, then read the specific number from it:

<?php

// an array which contains all possible numbers
$numbers = [
    3 => 11,
    5 => 15,
    7 => 19,
];

// the given value for `$a`
$a = 3;

// read the value for `$b` from numbers array
$b = $numbers[$a];

// do something with it
echo $b; // 11