1

I have a code like this

<?php if 
($trx->de_amount2 == '10000' ||$trx->de_amount2 == '15000'||$trx->de_amount2 == '20000'||$trx->de_amount2 == '25000'||$trx->de_amount2 == '30000' ):?>
 ok
<?php else:?>
no
<?php endif;?>

I want to make multiples of numbers from 5000 to 1 million with a simple code not like this

$trx->de_amount2 == '10000' ||$trx->de_amount2 == '15000'

How do I do that?

Emma
  • 27,428
  • 11
  • 44
  • 69
yagami cell
  • 147
  • 12

1 Answers1

0

Use in_array with range.

if(in_array($trx->de_amount2, range(5000, 1000000, 5000))){
    echo "ok";
}else{
    echo "not ok";
}

Range creates an array with all values between 5000 and 1000000 with 5000 increments.
In_array checks if the value is in the array (range).

Andreas
  • 23,610
  • 6
  • 30
  • 62