-2

Hello everyone please help me i want call function on every +5 value

php example

$value = $_GET['total_refer'];

i want call function on 5, 10, 15, 20

If($value == 5) // call function on if value = 5, 10, 15, 20
{
  // Call function
}

Please if you have any logic please say us.

Thankyou

ndm
  • 59,784
  • 9
  • 71
  • 110
  • https://www.php.net/manual/en/language.operators.arithmetic.php – aynber May 04 '21 at 11:55
  • https://www.php.net/manual/en/control-structures.for.php and then check with `%` https://www.php.net/manual/en/language.operators.arithmetic.php or if you don't need the other numbers just `$i+=5`. – AbraCadaver May 04 '21 at 11:55
  • Let me know if my answer worked for you :) – Example person May 04 '21 at 12:05
  • Really basic structures are so hard? `"; ` – biesior May 04 '21 at 12:05
  • Actually, your question after editing is quite **different**. Guys answered you how to deal with modulo, as you asked in the context of iteration (`$i++`) but if you want to check if `$_GET` value is in some range, you should rather use another approach i.e. `if(in_array($value, [5,10,15,20]))` – biesior May 04 '21 at 12:48

1 Answers1

0

Try:

Without for loop:

if ($value >= 5 && $value <= 20 && $value % 5 == 0) {
  myFunc(); // change to function name
}

for ($value = 0; $value <= 100; $value++) { // if using loop
  if ($value % 5 == 0 && $value != 0) {
    myfunc(); // change to function name
  }
} // do not use for loop if not needed :)

or

for ($value = 5; $value <= 100; $value++) {
  if ($value % 5 == 0) {
    myfunc();
  }
}

middle: 0 and values that are not divisible by 5
finally, if no middle values are required, you can use just a loop with proper start, end, and step.

for ($value = 5; $value <= 20; $value += 5) {
  myFunc();
}
Example person
  • 3,198
  • 3
  • 18
  • 45