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') );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lAKTt
function name:  (null)
number of ops:  12
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, <array>
   27     1        INIT_FCALL                                               'var_dump'
   28     2        INIT_FCALL                                               'pack_array_of_bools_to_string'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
   29     6        INIT_FCALL                                               'unpack_string_to_array_of_bools'
          7        SEND_VAL                                                 '1101001100010'
          8        DO_FCALL                                      0  $3      
          9        SEND_VAR                                                 $3
         10        DO_ICALL                                                 
   30    11      > RETURN                                                   1

Function pack_array_of_bools_to_string:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
Branch analysis from position: 6
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
Branch analysis from position: 6
filename:       /in/lAKTt
function name:  pack_array_of_bools_to_string
number of ops:  18
compiled vars:  !0 = $bools, !1 = $str, !2 = $l, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, ''
    6     2        COUNT                                            ~5      !0
          3        ASSIGN                                                   !2, ~5
    7     4        ASSIGN                                                   !3, 0
          5      > JMP                                                      ->12
    8     6    > > JMPZ                                                     !0, ->9
          7    >   QM_ASSIGN                                        ~8      '1'
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~8      '0'
         10    >   ASSIGN_OP                                     8          !1, ~8
    7    11        PRE_INC                                                  !3
         12    >   IS_SMALLER                                               !3, !2
         13      > JMPNZ                                                    ~11, ->6
   10    14    >   VERIFY_RETURN_TYPE                                       !1
         15      > RETURN                                                   !1
   11    16*       VERIFY_RETURN_TYPE                                       
         17*     > RETURN                                                   null

End of function pack_array_of_bools_to_string

Function unpack_string_to_array_of_bools:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 7
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 7
Branch analysis from position: 14
Branch analysis from position: 7
filename:       /in/lAKTt
function name:  unpack_string_to_array_of_bools
number of ops:  18
compiled vars:  !0 = $packed, !1 = $arr, !2 = $l, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        ASSIGN                                                   !1, <array>
   16     2        STRLEN                                           ~5      !0
          3        SUB                                              ~6      ~5, 1
          4        ASSIGN                                                   !2, ~6
   17     5        ASSIGN                                                   !3, 0
          6      > JMP                                                      ->12
   18     7    >   FETCH_DIM_R                                      ~10     !0, !3
          8        IS_IDENTICAL                                     ~11     ~10, '1'
          9        ASSIGN_DIM                                               !1
         10        OP_DATA                                                  ~11
   17    11        PRE_INC                                                  !3
         12    >   IS_SMALLER                                               !3, !2
         13      > JMPNZ                                                    ~13, ->7
   20    14    >   VERIFY_RETURN_TYPE                                       !1
         15      > RETURN                                                   !1
   21    16*       VERIFY_RETURN_TYPE                                       
         17*     > RETURN                                                   null

End of function unpack_string_to_array_of_bools

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.64 ms | 1402 KiB | 17 Q