3v4l.org

run code in 500+ PHP versions simultaneously
<?php function detectLanguage(array $langs, string $header): ?string { $s = strtolower($header); // case insensitive $s = strtr($s, '_', '-'); // cs_CZ means cs-CZ rsort($langs); // first more specific preg_match_all('#(' . implode('|', $langs) . ')(?:-[^\s,;=]+)?\s*(?:;\s*q=([0-9.]+))?#', $s, $matches); if (!$matches[0]) { return null; } $max = 0; $lang = null; foreach ($matches[1] as $key => $value) { $q = $matches[2][$key] === '' ? 1.0 : (float) $matches[2][$key]; if ($q > $max) { $max = $q; $lang = $value; } } return $lang; } echo detectLanguage(['en', 'fr', 'zn'], 'cs,en;q=0.9,fr;q=0.8,zh-CN;q=0.7,zh;q=0.6');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UJnKb
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                                   'detectlanguage'
          1        SEND_VAL                                                     <array>
          2        SEND_VAL                                                     'cs%2Cen%3Bq%3D0.9%2Cfr%3Bq%3D0.8%2Czh-CN%3Bq%3D0.7%2Czh%3Bq%3D0.6'
          3        DO_FCALL                                          0  $0      
          4        ECHO                                                         $0
          5      > RETURN                                                       1

Function detectlanguage:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 46
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 46
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 45
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 45
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 45
Branch analysis from position: 43
Branch analysis from position: 45
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
filename:       /in/UJnKb
function name:  detectLanguage
number of ops:  51
compiled vars:  !0 = $langs, !1 = $header, !2 = $s, !3 = $matches, !4 = $max, !5 = $lang, !6 = $value, !7 = $key, !8 = $q
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    5     2        INIT_FCALL                                                   'strtolower'
          3        SEND_VAR                                                     !1
          4        DO_ICALL                                             $9      
          5        ASSIGN                                                       !2, $9
    6     6        FRAMELESS_ICALL_3                strtr               ~11     !2, '_'
          7        OP_DATA                                                      '-'
          8        ASSIGN                                                       !2, ~11
    7     9        INIT_FCALL                                                   'rsort'
         10        SEND_REF                                                     !0
         11        DO_ICALL                                                     
    8    12        INIT_FCALL                                                   'preg_match_all'
         13        FRAMELESS_ICALL_2                implode             ~14     '%7C', !0
         14        CONCAT                                               ~15     '%23%28', ~14
         15        CONCAT                                               ~16     ~15, '%29%28%3F%3A-%5B%5E%5Cs%2C%3B%3D%5D%2B%29%3F%5Cs%2A%28%3F%3A%3B%5Cs%2Aq%3D%28%5B0-9.%5D%2B%29%29%3F%23'
         16        SEND_VAL                                                     ~16
         17        SEND_VAR                                                     !2
         18        SEND_REF                                                     !3
         19        DO_ICALL                                                     
   10    20        FETCH_DIM_R                                          ~18     !3, 0
         21        BOOL_NOT                                             ~19     ~18
         22      > JMPZ                                                         ~19, ->24
   11    23    > > RETURN                                                       null
   14    24    >   ASSIGN                                                       !4, 0
   15    25        ASSIGN                                                       !5, null
   16    26        FETCH_DIM_R                                          ~22     !3, 1
         27      > FE_RESET_R                                           $23     ~22, ->46
         28    > > FE_FETCH_R                                           ~24     $23, !6, ->46
         29    >   ASSIGN                                                       !7, ~24
   17    30        FETCH_DIM_R                                          ~26     !3, 2
         31        FETCH_DIM_R                                          ~27     ~26, !7
         32        IS_IDENTICAL                                                 ~27, ''
         33      > JMPZ                                                         ~28, ->36
         34    >   QM_ASSIGN                                            ~29     1
         35      > JMP                                                          ->40
         36    >   FETCH_DIM_R                                          ~30     !3, 2
         37        FETCH_DIM_R                                          ~31     ~30, !7
         38        CAST                                              5  ~32     ~31
         39        QM_ASSIGN                                            ~29     ~32
         40    >   ASSIGN                                                       !8, ~29
   18    41        IS_SMALLER                                                   !4, !8
         42      > JMPZ                                                         ~34, ->45
   19    43    >   ASSIGN                                                       !4, !8
   20    44        ASSIGN                                                       !5, !6
   16    45    > > JMP                                                          ->28
         46    >   FE_FREE                                                      $23
   24    47        VERIFY_RETURN_TYPE                                           !5
         48      > RETURN                                                       !5
   25    49*       VERIFY_RETURN_TYPE                                           
         50*     > RETURN                                                       null

End of function detectlanguage

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.99 ms | 1453 KiB | 17 Q