3v4l.org

run code in 300+ PHP versions simultaneously
<?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') );
Output for 7.0.0 - 7.0.1
Parse error: syntax error, unexpected 'var_dump' (T_STRING) in /in/mrb8f on line 27
Process exited with code 255.
Output for 5.5.24 - 5.5.30, 5.6.8 - 5.6.16
Parse error: syntax error, unexpected ':', expecting '{' in /in/mrb8f on line 3
Process exited with code 255.

preferences:
166.29 ms | 1395 KiB | 25 Q