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 = 29, Position 2 = 30
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 77) Position 1 = 34, Position 2 = 52
Branch analysis from position: 34
2 jumps found. (Code = 78) Position 1 = 35, Position 2 = 52
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 42
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 51
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
Branch analysis from position: 51
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
filename:       /in/UJnKb
function name:  detectLanguage
number of ops:  57
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        INIT_FCALL                                               'strtr'
          7        SEND_VAR                                                 !2
          8        SEND_VAL                                                 '_'
          9        SEND_VAL                                                 '-'
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !2, $11
    7    12        INIT_FCALL                                               'rsort'
         13        SEND_REF                                                 !0
         14        DO_ICALL                                                 
    8    15        INIT_FCALL                                               'preg_match_all'
         16        INIT_FCALL                                               'implode'
         17        SEND_VAL                                                 '%7C'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $14     
         20        CONCAT                                           ~15     '%23%28', $14
         21        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'
         22        SEND_VAL                                                 ~16
         23        SEND_VAR                                                 !2
         24        SEND_REF                                                 !3
         25        DO_ICALL                                                 
   10    26        FETCH_DIM_R                                      ~18     !3, 0
         27        BOOL_NOT                                         ~19     ~18
         28      > JMPZ                                                     ~19, ->30
   11    29    > > RETURN                                                   null
   14    30    >   ASSIGN                                                   !4, 0
   15    31        ASSIGN                                                   !5, null
   16    32        FETCH_DIM_R                                      ~22     !3, 1
         33      > FE_RESET_R                                       $23     ~22, ->52
         34    > > FE_FETCH_R                                       ~24     $23, !6, ->52
         35    >   ASSIGN                                                   !7, ~24
   17    36        FETCH_DIM_R                                      ~26     !3, 2
         37        FETCH_DIM_R                                      ~27     ~26, !7
         38        IS_IDENTICAL                                             ~27, ''
         39      > JMPZ                                                     ~28, ->42
         40    >   QM_ASSIGN                                        ~29     1
         41      > JMP                                                      ->46
         42    >   FETCH_DIM_R                                      ~30     !3, 2
         43        FETCH_DIM_R                                      ~31     ~30, !7
         44        CAST                                          5  ~32     ~31
         45        QM_ASSIGN                                        ~29     ~32
         46    >   ASSIGN                                                   !8, ~29
   18    47        IS_SMALLER                                               !4, !8
         48      > JMPZ                                                     ~34, ->51
   19    49    >   ASSIGN                                                   !4, !8
   20    50        ASSIGN                                                   !5, !6
   16    51    > > JMP                                                      ->34
         52    >   FE_FREE                                                  $23
   24    53        VERIFY_RETURN_TYPE                                       !5
         54      > RETURN                                                   !5
   25    55*       VERIFY_RETURN_TYPE                                       
         56*     > RETURN                                                   null

End of function detectlanguage

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.32 ms | 1455 KiB | 19 Q