如何用php选择范围如果条件[关闭]

I have a some auto-generation string with number. It's can be from 0 to 99. How i can choose each "2,3,4" from this? (x2,x3,x4 etc)

$n = 53;

if($i == ?){ echo "there is 3";}

What i need to print instead "?" symbol?

Thanks.

really just guessing here:

<?php

$i=23;//13,33,43,9999999993
if(substr($i,-1) == 3){ 
echo "there is 3";
}

the code

substr($i,-1)

returns the last character of the string $i


to cover 2 or 3 or 4

$i=24;
if(in_array(substr($i,-1),array(2,3,4))){ 
echo "ends in 2 or 3 or 4";
}

The algorithmic solution here would be:

if ($i % 10 == 3) {

% is the modulus operator. Here dividing 53 by 10 for example, thus leaving 3 as result for the comparison.

If your question is to tell if a string contains a character (like 53 contains a 3), you can use strpos or strstr (there are probably several other functions that do this too):

$i = "53";
if(strpos($i, "3") !== FALSE) {
    echo "There is a 3 in $i";
}