CKTIS / PHP
Integer remainder with assignment (%=)
Wrap a nonnegative counter into the index range by storing its remainder modulo the cycle length.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
$value %= $operandWrap a nonnegative counter into the index range by storing its remainder modulo the cycle length. The length must be positive.
Operands are converted to integers. A nonzero remainder has the sign of the dividend. A divisor of zero raises DivisionByZeroError.
Evaluation
$value = 17; $value %= 5;→2$value = (-17); $value %= 5;→-2$value = 12; $value %= 4;→0
Examples
<?php
$value = 17;
$value %= 5;
echo json_encode($value), PHP_EOL;
$value = (-17);
$value %= 5;
echo json_encode($value), PHP_EOL;
$value = 12;
$value %= 4;
echo json_encode($value), PHP_EOL;
Result
2 -2 0