- var_dump: documentation ( source)
<?php
$inputArduino = 17;
var_dump(unparserPlayerRounds($inputArduino));
function unparserPlayerRounds(int $bitNumber): array
{
$playerArray = [];
$players = [
32 => 'Player 6',
16 => 'Player 5',
8 => 'Player 4',
4 => 'Player 3',
2 => 'Player 2',
1 => 'Player 1',
];
while($bitNumber !== 0) {
foreach ($players as $bitValue => $player) {
if ($bitNumber >= $bitValue) {
$playerArray[] = $player;
$bitNumber -= $bitValue;
}
}
}
return $playerArray;
}