Another way to get the population count when you don't have the gmp extension is using bitwise operations:
<?php
$int = 133; // 10000101
for($count = 0; $int != 0; $count++) // repeat until $int is 0 (and count the amount of steps it takes in $count)
{
$int = $int & $int-1; // remove the right most 1 from $int using the bitwise and operator
}
echo $count; // 3
?>
This is Kernighan's population count.
https://youtu.be/ZRNO-ewsNcQ?t=510 has a nice explanation on how it works