PHP添加到模数

I want to display rows with 4 items, per row but I want to complete my rows

How can I always get : count(myarray) % 4 = 0 ?

let's say I have : count = 29 , how can I get : 3 ?

29 + 3  = 32  --> 32 % 4 = 0

How about

4 - count(myarray) % 4

x - count(myarray) % x

It will give you the rest.

And as pointed out by the comment below, if you want to avoid having 4 as the result of a complete row, use this :

(4 - count(myarray) % 4) % 4

(x - count(myarray) % x) % x
$foo = 29;
$rounded_up = $foo + (4 - ($foo % 4));

29 % 4 -> 1
4 - 1 -> 3
29 + 3 -> 32
32 % 4 -> 0

Try with:

$count  = count($array);
$modulo = 4;
$result = $modulo - $count % $modulo;

This is a math question, not a programming question. But to answer it: the missing number is (4-(count % 4)) % 4. Example: count=29 , count%4=1, 4-1=3. The extra %4 is to catch edge cases like 28: 28%4=0; 4-0=4; 4%4=0.