3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function pack_array_of_bools_to_string(array $bools): string { $str = ''; $l = count($bools); for ($i = 0; $i < $l; ++$i) { $str .= $bools ? '1' : '0'; } return $str; } function unpack_string_to_array_of_bools(string $packed): array { $arr = []; $l = strlen($packed) - 1; for ($i = 0; $i < $l; ++$i) { $arr[] = $packed[$i] === '1'; } return $arr; } $arr = [ true, true, false, true, false, false, true, true, false, false, false, true, false ]; var_dump( pack_array_of_bools_to_string($arr), unpack_string_to_array_of_bools('1101001100010') );
based on mrb8f
Output for 7.0.0 - 7.2.0
string(13) "1111111111111" array(12) { [0]=> bool(true) [1]=> bool(true) [2]=> bool(false) [3]=> bool(true) [4]=> bool(false) [5]=> bool(false) [6]=> bool(true) [7]=> bool(true) [8]=> bool(false) [9]=> bool(false) [10]=> bool(false) [11]=> bool(true) }
Output for 5.3.21 - 5.6.28
Parse error: syntax error, unexpected ':', expecting '{' in /in/lAKTt on line 3
Process exited with code 255.