3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getListFromLocales(): array { return array_filter(ResourceBundle::getLocales(''), function ($value) { return strpos($value, '_') === false; }); } function getListFromLanguages(): array { $resourceBundle = new ResourceBundle('en', 'ICUDATA-lang', false); $languagesBundle = $resourceBundle['Languages']; $languages = []; foreach ($languagesBundle as $languageCode => $languageName) { $languages[] = $languageCode; } return $languages; } function languageForEndUser($language): string { return Locale::getDisplayLanguage($language, $language) . ' (' . Locale::getDisplayLanguage($language) . ')'; } $list1 = getListFromLocales(); $list2 = getListFromLanguages(); echo 'languages in list1: ' . count($list1) . PHP_EOL; echo 'languages in list2: ' . count($list2) . PHP_EOL; echo 'languages that exists in list1, but not in list2: ' . count(array_diff($list1, $list2)) . PHP_EOL; echo 'languages that exists in list2, but not in list1: ' . count(array_diff($list2, $list1)) . PHP_EOL; Locale::setDefault('fr'); // Assume end-user speaks french echo 'examples of language for end-user: ' . PHP_EOL; echo ' - ' . languageForEndUser('en') . PHP_EOL; echo ' - ' . languageForEndUser('fr') . PHP_EOL; echo ' - ' . languageForEndUser('ko') . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TS292
function name:  (null)
number of ops:  53
compiled vars:  !0 = $list1, !1 = $list2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'getlistfromlocales'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   29     3        INIT_FCALL                                               'getlistfromlanguages'
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !1, $4
   31     6        COUNT                                            ~6      !0
          7        CONCAT                                           ~7      'languages+in+list1%3A+', ~6
          8        CONCAT                                           ~8      ~7, '%0A'
          9        ECHO                                                     ~8
   32    10        COUNT                                            ~9      !1
         11        CONCAT                                           ~10     'languages+in+list2%3A+', ~9
         12        CONCAT                                           ~11     ~10, '%0A'
         13        ECHO                                                     ~11
   33    14        INIT_FCALL                                               'array_diff'
         15        SEND_VAR                                                 !0
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                         $12     
         18        COUNT                                            ~13     $12
         19        CONCAT                                           ~14     'languages+that+exists+in+list1%2C+but+not+in+list2%3A+', ~13
         20        CONCAT                                           ~15     ~14, '%0A'
         21        ECHO                                                     ~15
   34    22        INIT_FCALL                                               'array_diff'
         23        SEND_VAR                                                 !1
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                         $16     
         26        COUNT                                            ~17     $16
         27        CONCAT                                           ~18     'languages+that+exists+in+list2%2C+but+not+in+list1%3A+', ~17
         28        CONCAT                                           ~19     ~18, '%0A'
         29        ECHO                                                     ~19
   36    30        INIT_STATIC_METHOD_CALL                                  'Locale', 'setDefault'
         31        SEND_VAL_EX                                              'fr'
         32        DO_FCALL                                      0          
   38    33        ECHO                                                     'examples+of+language+for+end-user%3A+%0A'
   39    34        INIT_FCALL                                               'languageforenduser'
         35        SEND_VAL                                                 'en'
         36        DO_FCALL                                      0  $21     
         37        CONCAT                                           ~22     '++++-+', $21
         38        CONCAT                                           ~23     ~22, '%0A'
         39        ECHO                                                     ~23
   40    40        INIT_FCALL                                               'languageforenduser'
         41        SEND_VAL                                                 'fr'
         42        DO_FCALL                                      0  $24     
         43        CONCAT                                           ~25     '++++-+', $24
         44        CONCAT                                           ~26     ~25, '%0A'
         45        ECHO                                                     ~26
   41    46        INIT_FCALL                                               'languageforenduser'
         47        SEND_VAL                                                 'ko'
         48        DO_FCALL                                      0  $27     
         49        CONCAT                                           ~28     '++++-+', $27
         50        CONCAT                                           ~29     ~28, '%0A'
         51        ECHO                                                     ~29
   42    52      > RETURN                                                   1

Function getlistfromlocales:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TS292
function name:  getListFromLocales
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_FCALL                                               'array_filter'
          1        INIT_STATIC_METHOD_CALL                                  'ResourceBundle', 'getLocales'
          2        SEND_VAL_EX                                              ''
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DECLARE_LAMBDA_FUNCTION                          ~1      [0]
    7     6        SEND_VAL                                                 ~1
    5     7        DO_ICALL                                         $2      
    7     8        VERIFY_RETURN_TYPE                                       $2
          9      > RETURN                                                   $2
    8    10*       VERIFY_RETURN_TYPE                                       
         11*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TS292
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        INIT_FCALL                                               'strpos'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '_'
          4        DO_ICALL                                         $1      
          5        TYPE_CHECK                                    4  ~2      $1
          6      > RETURN                                                   ~2
    7     7*     > RETURN                                                   null

End of Dynamic Function 0

End of function getlistfromlocales

Function getlistfromlanguages:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/TS292
function name:  getListFromLanguages
number of ops:  20
compiled vars:  !0 = $resourceBundle, !1 = $languagesBundle, !2 = $languages, !3 = $languageName, !4 = $languageCode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   NEW                                              $5      'ResourceBundle'
          1        SEND_VAL_EX                                              'en'
          2        SEND_VAL_EX                                              'ICUDATA-lang'
          3        SEND_VAL_EX                                              <false>
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $5
   13     6        FETCH_DIM_R                                      ~8      !0, 'Languages'
          7        ASSIGN                                                   !1, ~8
   15     8        ASSIGN                                                   !2, <array>
   16     9      > FE_RESET_R                                       $11     !1, ->15
         10    > > FE_FETCH_R                                       ~12     $11, !3, ->15
         11    >   ASSIGN                                                   !4, ~12
   17    12        ASSIGN_DIM                                               !2
         13        OP_DATA                                                  !4
   16    14      > JMP                                                      ->10
         15    >   FE_FREE                                                  $11
   20    16        VERIFY_RETURN_TYPE                                       !2
         17      > RETURN                                                   !2
   21    18*       VERIFY_RETURN_TYPE                                       
         19*     > RETURN                                                   null

End of function getlistfromlanguages

Function languageforenduser:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TS292
function name:  languageForEndUser
number of ops:  15
compiled vars:  !0 = $language
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        INIT_STATIC_METHOD_CALL                                  'Locale', 'getDisplayLanguage'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $1      
          5        CONCAT                                           ~2      $1, '+%28'
          6        INIT_STATIC_METHOD_CALL                                  'Locale', 'getDisplayLanguage'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0  $3      
          9        CONCAT                                           ~4      ~2, $3
         10        CONCAT                                           ~5      ~4, '%29'
         11        VERIFY_RETURN_TYPE                                       ~5
         12      > RETURN                                                   ~5
   26    13*       VERIFY_RETURN_TYPE                                       
         14*     > RETURN                                                   null

End of function languageforenduser

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.51 ms | 1011 KiB | 21 Q