3v4l.org

run code in 500+ PHP versions simultaneously
<?php define('WAR_CODES', [ ' ' => '', // World War 1 'A' => 'Allied Forces', 'AFG' => 'Australian - War on Terrorism', 'AGX' => 'Act of Grace', 'ALX' => 'Algeria - World War 2', 'ARG' => 'Argentina - Gulf War', 'ARX' => 'Argentina - World War 2', 'BAG' => 'Bahrain - Gulf War', 'BAL' => 'Peacekeeping - Balkans', 'BCG' => 'Bangladesh - Gulf War', 'BG' => 'Belgium - World War 1', 'BGG' => 'Belgium - Gulf War', 'BGK' => 'Belgium - Korean War', 'BGX' => 'Belgium - World War 2', 'BRX' => 'Brazil - World War 2', 'BUG' => 'Bulgaria - Gulf War', 'BUR' => 'Burma', 'BUX' => 'Bulgaria - World War 2', 'CAM' => 'Australian - Cambodian Service', 'CCG' => 'Canadian - Gulf War', 'CHX' => 'China - World War 2', 'CIX' => 'Chile - World War 2', 'CLK' => 'Colombia - Korean War', 'CN' => 'Canadian - World War 1', 'CNK' => 'Canadian - Korean War', 'CNS' => 'Canadian - Other Service', 'CNX' => 'Canadian - World War 2', 'CON' => 'Peacekeeping - Congo', 'CYP' => 'Peacekeeping - Cyprus', 'CZG' => 'Czechoslovakia - Gulf War', 'CZX' => 'Czechoslovakia - World War 2', 'DEG' => 'Denmark - Gulf War', 'DNK' => 'Denmark - Korean War', 'DNX' => 'Denmark - World War 2', 'EGG' => 'Egypt - Gulf War', 'EGX' => 'Egypt - World War 2', 'EGY' => 'Peacekeeping - Egypt', 'ESX' => 'Estonia - World War 2', 'ET' => 'Australian - East Timor Service', 'ETK' => 'Ethiopia - Korean War', 'ETX' => 'Ethiopia - World War 2', 'FIJ' => 'Fiji', 'FIX' => 'Finland - World War 2', 'FR' => 'France - World War 1', 'FRG' => 'France - Gulf War', 'FRK' => 'France - Korean War', 'FRX' => 'France - World War 2', 'FW' => 'Australian - World War 1', 'GHA' => 'Ghana', 'GR' => 'Greece - World War 1', 'GRE' => 'Peacekeeping - Greece', 'GRG' => 'Greece - Gulf War', 'GRK' => 'Greece - Korean War', 'GRX' => 'Greece - World War 2', 'GW' => 'Australian - Gulf War Service', 'HKS' => 'Hong Kong', 'HKX' => 'Hong Kong - World War 2', 'HLG' => 'Netherlands - Gulf War', 'HLK' => 'Netherlands - Korea', 'HLX' => 'Netherlands - World War 2', 'HUX' => 'Hungary - World War 2', 'IDA' => 'Peacekeeping - Indonesia', 'IND' => 'India', 'IQ' => 'Australian - War in Iraq', 'ISR' => 'Peacekeeping - Israel', 'IT' => 'Italy - World War 1', 'ITG' => 'Italy - Gulf War', 'ITK' => 'Italy - Korean War', 'ITX' => 'Italy - World War 2', 'IV' => 'Indigenous Veterans of PNG', 'JA' => 'Japan - World War 1', 'KM' => 'Australian - Korean/Malayan Service', 'KO' => 'South Korea - Korean War', 'KOS' => 'South Korea - Vietnam War', 'KSH' => 'Peacekeeping - Kashmir', 'KUG' => 'Kuwait - Gulf War', 'KYA' => 'Kenya', 'LAX' => 'Latvia - World War 2', 'LBX' => 'Liberia - World War 2', 'LXK' => 'Luxembourg - Korean War', 'MAL' => 'Malaysian Pensioners', 'MAR' => 'Allied Mariner- World War 2', 'MAU' => 'Mauritius', 'MLS' => 'Malaysia/Singapore', 'MO' => 'Montenegro - World War 1', 'MOG' => 'Morocco - Gulf War', 'MTX' => 'Malta - World War 2', 'MWI' => 'Malawi', 'N' => 'New Zealand - World War 1', 'NBA' => 'Australian - Namibian Service', 'NCG' => 'New Zealand - Gulf War', 'NF' => 'Newfoundland', 'NG' => 'New Guinea Civilians', 'NGR' => 'Nigeria', 'NIG' => 'Niger - Gulf War', 'NK' => 'New Zealand - Korean War', 'NRD' => 'Northern Zimbabwe (Rhodesia)', 'NSM' => 'New Zealand - Serving Member', 'NSS' => 'New Zealand Special O\'seas Service', 'NSW' => 'New Zealand Merchant Mariner - WW2', 'NWG' => 'Norway - Gulf War', 'NWK' => 'Norway - Korean War', 'NWX' => 'Norway - World War 2', 'NX' => 'New Zealand - World War 2', 'OMG' => 'Oman - Gulf War', 'P' => 'British - World War 1', 'PAD' => 'British Admiralty', 'PAG' => 'Pakistan - Gulf War', 'PAL' => 'Peacekeeping - Palestine', 'PAM' => 'British Air Ministry', 'PAX' => 'Panama - World War 2', 'PCA' => 'British Crown Agents', 'PCG' => 'British - Gulf War', 'PCR' => 'British Ministry O\'seas Development', 'PCV' => 'British Civilians', 'PHK' => 'Philippines - Korean War', 'PHS' => 'Philippines - Vietnam War', 'PHX' => 'Philippines - World War 2', 'PK' => 'British - Korean/Malayan Service', 'PLG' => 'Poland - Gulf War', 'PLX' => 'Poland - World War 2', 'PMS' => 'British Merchant Mariner - WW1', 'PO' => 'Portugal - World War 1', 'PSM' => 'British Serving Member', 'PSW' => 'British Merchant Mariner - WW2', 'PWO' => 'British War Office', 'PX' => 'British - World War 2', 'QAG' => 'Qatar - Gulf War', 'RD' => 'Zimbabwe (Rhodesia) - World War 1', 'RDX' => 'Zimbabwe (Rhodesia) - World War 2', 'RM' => 'Romania - World War 1', 'RU' => 'Russia - World War 1', 'RUG' => 'Russia - Gulf War', 'RUX' => 'Russia - World War 2', 'SA' => 'South Africa - World War 1', 'SAG' => 'Saudi Arabia - Gulf War', 'SAX' => 'South Africa - World War 2', 'SCG' => 'Sierra Leone - Gulf War', 'SE' => 'Serbia - World War 1', 'SEG' => 'Senegal - Gulf War', 'SIN' => 'Peacekeeping - Sinai', 'SL' => 'Sierra Leone', 'SM' => 'Australian - Serving Member', 'SO' => 'Australian - Somalian Service', 'SPG' => 'Spain - Gulf War', 'SR' => 'Australian - Malayan Emergency', 'SS' => 'Australian Special Overseas Service', 'SUD' => 'Sudan', 'SWK' => 'Sweden - Korean War', 'SWP' => 'Australian Merchant Mariner - WW2', 'SYG' => 'Syria - Gulf War', 'SYR' => 'Peacekeeping - Syria', 'SYX' => 'Syria - World War 2', 'THK' => 'Thailand - Korean War', 'THS' => 'Thailand - Vietnam War', 'TRG' => 'Turkey - Gulf War', 'TRK' => 'Turkey - Korean War', 'TZA' => 'Tanzania (Tanzanyika/Zanzibar)', 'UAG' => 'United Arab Emirates - Gulf War', 'UB' => 'Australian - Ubon 1965-68', 'URX' => 'Uruguay - World War 2', 'US' => 'United States - World War 1', 'USG' => 'United States - Gulf War', 'USK' => 'United States - Korean War', 'USS' => 'United States - Vietnam War', 'USX' => 'United States - World War 2', 'V' => 'Australian - Serving Member', 'VEX' => 'Venezuela - World War 2', 'VNS' => 'South Vietnam - Vietnam War', 'X' => 'Australian - World War 2', 'YEM' => 'Peacekeeping - Yemen', 'YGX' => 'Yugoslavia - World War 2', 'YU' => 'Australian - Yugoslavian Service', 'ZIM' => 'Peacekeeping - Zimbabwe', ]); $groups = [1 => '']; foreach (WAR_CODES as $code => $description) { switch (strlen($code)) { case 1: $groups[1] .= $code; break; case 2: $groups[2][$code[0]][] = $code[1]; break; case 3: $groups[3][$code[0]][$code[1]][] = $code[2]; break; } } $groups[1] = "[{$groups[1]}]\d{6}"; foreach ($groups[2] as $first => &$seconds) { $seconds = count($seconds) === 1 ? "$first{$seconds[0]}" : sprintf('%s[%s]', $first, implode($seconds)); } $groups[2] = '(?:' . implode('|', $groups[2]) . ')\d{5}'; foreach ($groups[3] as $first => &$seconds) { foreach ($seconds as $second => &$thirds) { $thirds = count($thirds) === 1 ? "$second{$thirds[0]}" : sprintf('%s[%s]', $second, implode($thirds)); } $seconds = count($seconds) === 1 ? "$first$thirds" : sprintf('%s(?:%s)', $first, implode('|', $seconds)); } $groups[3] = '(?:' . implode('|', $groups[3]) . ')\d{4}'; ksort($groups); echo implode("\n|", $groups);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 38
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 38
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 27
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 38
2 jumps found. (Code = 125) Position 1 = 47, Position 2 = 65
Branch analysis from position: 47
2 jumps found. (Code = 126) Position 1 = 48, Position 2 = 65
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 57
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 65
2 jumps found. (Code = 125) Position 1 = 74, Position 2 = 111
Branch analysis from position: 74
2 jumps found. (Code = 126) Position 1 = 75, Position 2 = 111
Branch analysis from position: 75
2 jumps found. (Code = 125) Position 1 = 77, Position 2 = 95
Branch analysis from position: 77
2 jumps found. (Code = 126) Position 1 = 78, Position 2 = 95
Branch analysis from position: 78
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 87
Branch analysis from position: 82
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
Branch analysis from position: 95
2 jumps found. (Code = 43) Position 1 = 99, Position 2 = 103
Branch analysis from position: 99
1 jumps found. (Code = 42) Position 1 = 109
Branch analysis from position: 109
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
Branch analysis from position: 103
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
Branch analysis from position: 95
Branch analysis from position: 111
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 111
Branch analysis from position: 65
Branch analysis from position: 38
filename:       /in/8ECVS
function name:  (null)
number of ops:  124
compiled vars:  !0 = $groups, !1 = $description, !2 = $code, !3 = $seconds, !4 = $first, !5 = $thirds, !6 = $second
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'define'
          1        SEND_VAL                                                     'WAR_CODES'
    4     2        SEND_VAL                                                     <array>
    3     3        DO_ICALL                                                     
  180     4        ASSIGN                                                       !0, <array>
  181     5        FETCH_CONSTANT                                       ~9      'WAR_CODES'
          6      > FE_RESET_R                                           $10     ~9, ->38
          7    > > FE_FETCH_R                                           ~11     $10, !1, ->38
          8    >   ASSIGN                                                       !2, ~11
  182     9        STRLEN                                               ~13     !2
  183    10        CASE                                                         ~13, 1
         11      > JMPNZ                                                        ~14, ->17
  186    12    >   CASE                                                         ~13, 2
         13      > JMPNZ                                                        ~14, ->20
  189    14    >   CASE                                                         ~13, 3
         15      > JMPNZ                                                        ~14, ->27
         16    > > JMP                                                          ->36
  184    17    >   ASSIGN_DIM_OP                    .=               8          !0, 1
         18        OP_DATA                                                      !2
  185    19      > JMP                                                          ->36
  187    20    >   FETCH_DIM_R                                          ~17     !2, 0
         21        FETCH_DIM_R                                          ~20     !2, 1
         22        FETCH_DIM_W                                          $16     !0, 2
         23        FETCH_DIM_W                                          $18     $16, ~17
         24        ASSIGN_DIM                                                   $18
         25        OP_DATA                                                      ~20
  188    26      > JMP                                                          ->36
  190    27    >   FETCH_DIM_R                                          ~22     !2, 0
         28        FETCH_DIM_R                                          ~24     !2, 1
         29        FETCH_DIM_R                                          ~27     !2, 2
         30        FETCH_DIM_W                                          $21     !0, 3
         31        FETCH_DIM_W                                          $23     $21, ~22
         32        FETCH_DIM_W                                          $25     $23, ~24
         33        ASSIGN_DIM                                                   $25
         34        OP_DATA                                                      ~27
  191    35      > JMP                                                          ->36
         36    >   FREE                                                         ~13
  181    37      > JMP                                                          ->7
         38    >   FE_FREE                                                      $10
  194    39        ROPE_INIT                                         3  ~31     '%5B'
         40        FETCH_DIM_R                                          ~29     !0, 1
         41        ROPE_ADD                                          1  ~31     ~31, ~29
         42        ROPE_END                                          2  ~30     ~31, '%5D%5Cd%7B6%7D'
         43        ASSIGN_DIM                                                   !0, 1
         44        OP_DATA                                                      ~30
  196    45        FETCH_DIM_W                                          $33     !0, 2
         46      > FE_RESET_RW                                          $34     $33, ->65
         47    > > FE_FETCH_RW                                          ~35     $34, !3, ->65
         48    >   ASSIGN                                                       !4, ~35
  197    49        COUNT                                                ~37     !3
         50        IS_IDENTICAL                                                 ~37, 1
         51      > JMPZ                                                         ~38, ->57
  198    52    >   NOP                                                          
         53        FETCH_DIM_R                                          ~39     !3, 0
         54        FAST_CONCAT                                          ~40     !4, ~39
         55        QM_ASSIGN                                            ~41     ~40
         56      > JMP                                                          ->63
  199    57    >   FRAMELESS_ICALL_1                implode             ~42     !3
         58        ROPE_INIT                                         4  ~44     !4
         59        ROPE_ADD                                          1  ~44     ~44, '%5B'
         60        ROPE_ADD                                          2  ~44     ~44, ~42
         61        ROPE_END                                          3  ~43     ~44, '%5D'
         62        QM_ASSIGN                                            ~41     ~43
  197    63    >   ASSIGN                                                       !3, ~41
  196    64      > JMP                                                          ->47
         65    >   FE_FREE                                                      $34
  201    66        FETCH_DIM_R                                          ~48     !0, 2
         67        FRAMELESS_ICALL_2                implode             ~49     '%7C', ~48
         68        CONCAT                                               ~50     '%28%3F%3A', ~49
         69        CONCAT                                               ~51     ~50, '%29%5Cd%7B5%7D'
         70        ASSIGN_DIM                                                   !0, 2
         71        OP_DATA                                                      ~51
  203    72        FETCH_DIM_W                                          $52     !0, 3
         73      > FE_RESET_RW                                          $53     $52, ->111
         74    > > FE_FETCH_RW                                          ~54     $53, !3, ->111
         75    >   ASSIGN                                                       !4, ~54
  204    76      > FE_RESET_RW                                          $56     !3, ->95
         77    > > FE_FETCH_RW                                          ~57     $56, !5, ->95
         78    >   ASSIGN                                                       !6, ~57
  205    79        COUNT                                                ~59     !5
         80        IS_IDENTICAL                                                 ~59, 1
         81      > JMPZ                                                         ~60, ->87
  206    82    >   NOP                                                          
         83        FETCH_DIM_R                                          ~61     !5, 0
         84        FAST_CONCAT                                          ~62     !6, ~61
         85        QM_ASSIGN                                            ~63     ~62
         86      > JMP                                                          ->93
  207    87    >   FRAMELESS_ICALL_1                implode             ~64     !5
         88        ROPE_INIT                                         4  ~66     !6
         89        ROPE_ADD                                          1  ~66     ~66, '%5B'
         90        ROPE_ADD                                          2  ~66     ~66, ~64
         91        ROPE_END                                          3  ~65     ~66, '%5D'
         92        QM_ASSIGN                                            ~63     ~65
  205    93    >   ASSIGN                                                       !5, ~63
  204    94      > JMP                                                          ->77
         95    >   FE_FREE                                                      $56
  209    96        COUNT                                                ~69     !3
         97        IS_IDENTICAL                                                 ~69, 1
         98      > JMPZ                                                         ~70, ->103
  210    99    >   NOP                                                          
        100        FAST_CONCAT                                          ~71     !4, !5
        101        QM_ASSIGN                                            ~72     ~71
        102      > JMP                                                          ->109
  211   103    >   FRAMELESS_ICALL_2                implode             ~73     '%7C', !3
        104        ROPE_INIT                                         4  ~75     !4
        105        ROPE_ADD                                          1  ~75     ~75, '%28%3F%3A'
        106        ROPE_ADD                                          2  ~75     ~75, ~73
        107        ROPE_END                                          3  ~74     ~75, '%29'
        108        QM_ASSIGN                                            ~72     ~74
  209   109    >   ASSIGN                                                       !3, ~72
  203   110      > JMP                                                          ->74
        111    >   FE_FREE                                                      $53
  213   112        FETCH_DIM_R                                          ~79     !0, 3
        113        FRAMELESS_ICALL_2                implode             ~80     '%7C', ~79
        114        CONCAT                                               ~81     '%28%3F%3A', ~80
        115        CONCAT                                               ~82     ~81, '%29%5Cd%7B4%7D'
        116        ASSIGN_DIM                                                   !0, 3
        117        OP_DATA                                                      ~82
  215   118        INIT_FCALL                                                   'ksort'
        119        SEND_REF                                                     !0
        120        DO_ICALL                                                     
  216   121        FRAMELESS_ICALL_2                implode             ~84     '%0A%7C', !0
        122        ECHO                                                         ~84
        123      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
130.57 ms | 492 KiB | 9 Q