3v4l.org

run code in 300+ PHP versions simultaneously
<?php $int = 5; $bits = []; function int_to_bools($int, $count) { $bools = []; for ($i = 0; $i < $count; $i++) { $bools[$i] = (bool)($int & (2 ** $i)); } return $bools; } function bools_to_int($bools) { $int = 0; foreach (array_values($bools) as $i => $bit) { $int |= ((int)$bit) << $i; } return $int; } $int = 5; $bools = int_to_bools($int, 10); var_dump($bools); $int = bools_to_int($bools); var_dump($int);
Output for 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array(10) { [0]=> bool(true) [1]=> bool(false) [2]=> bool(true) [3]=> bool(false) [4]=> bool(false) [5]=> bool(false) [6]=> bool(false) [7]=> bool(false) [8]=> bool(false) [9]=> bool(false) } int(5)
Output for 5.5.0 - 5.5.35
Parse error: syntax error, unexpected '*' in /in/6Hk68 on line 11
Process exited with code 255.

preferences:
101.1 ms | 1738 KiB | 4 Q