3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = [ (object)['title' => 'a test title'], (object)['title' => 'second title'], (object)['title' => 'Привет!'], (object)['title' => 'çà'] ]; // Instantiating the single-byte alphabetical groups... $groups = array_fill_keys(array_merge(range('a','z'), ['other']), []); //var_export($groups); //echo "\n---\n"; // Grouping by first (potentially multi-byte) letter... $translate = [ 'à' => 'a', 'á' => 'a', 'ả' => 'a', 'ạ' => 'a', 'ã' => 'a', 'â' => 'a', 'ầ' => 'a', 'ấ' => 'a', 'ẩ' => 'a', 'ậ' => 'a', 'ẫ' => 'a', 'ă' => 'a', 'ằ' => 'a', 'ắ' => 'a', 'ẳ' => 'a', 'ặ' => 'a', 'ẵ' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'đ' => 'd', 'è' => 'e', 'é' => 'e', 'ẻ' => 'e', 'ẹ' => 'e', 'ẽ' => 'e', 'ê' => 'e', 'ề' => 'e', 'ế' => 'e', 'ể' => 'e', 'ệ' => 'e', 'ễ' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'ỉ' => 'i', 'ị' => 'i', 'ĩ' => 'i', 'î' => 'i', 'ï' => 'i', 'ò' => 'o', 'ó' => 'o', 'ỏ' => 'o', 'ọ' => 'o', 'õ' => 'o', 'ô' => 'o', 'ồ' => 'o', 'ố' => 'o', 'ổ' => 'o', 'ộ' => 'o', 'ỗ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ũ' => 'u', 'ü' => 'u', 'ů' => 'u', 'ủ' => 'u', 'ụ' => 'u', 'ư' => 'u', 'ứ' => 'u', 'ừ' => 'u', 'ữ' => 'u', 'ử' => 'u', 'ự' => 'u', 'ć' => 'c', 'ĉ' => 'c', 'ç' => 'c', 'ç' => 'c', 'ñ' => 'n', 'ý' => 'y', 'ỳ' => 'y', 'ỷ' => 'y', 'ỵ' => 'y', 'ỹ' => 'y', 'ŷ' => 'y', 'ÿ' => 'y' ]; foreach ($items as $item) { $first = strtr(mb_strtolower(mb_substr($item->title, 0, 1, "UTF-8"), "UTF-8"), $translate); if (isset($groups[$first])) { $groups[$first] = [$first, $item]; } else { $groups['other'] = [$first, $item]; } } var_export($groups);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 53
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 53
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 48
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
filename:       /in/PM03n
function name:  (null)
number of ops:  58
compiled vars:  !0 = $items, !1 = $groups, !2 = $translate, !3 = $item, !4 = $first
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   CAST                                          8  ~5      <array>
          1        INIT_ARRAY                                       ~6      ~5
    4     2        CAST                                          8  ~7      <array>
          3        ADD_ARRAY_ELEMENT                                ~6      ~7
    5     4        CAST                                          8  ~8      <array>
          5        ADD_ARRAY_ELEMENT                                ~6      ~8
    6     6        CAST                                          8  ~9      <array>
          7        ADD_ARRAY_ELEMENT                                ~6      ~9
    2     8        ASSIGN                                                   !0, ~6
   10     9        INIT_FCALL                                               'array_fill_keys'
         10        INIT_FCALL                                               'array_merge'
         11        INIT_FCALL                                               'range'
         12        SEND_VAL                                                 'a'
         13        SEND_VAL                                                 'z'
         14        DO_ICALL                                         $11     
         15        SEND_VAR                                                 $11
         16        SEND_VAL                                                 <array>
         17        DO_ICALL                                         $12     
         18        SEND_VAR                                                 $12
         19        SEND_VAL                                                 <array>
         20        DO_ICALL                                         $13     
         21        ASSIGN                                                   !1, $13
   15    22        ASSIGN                                                   !2, <array>
   27    23      > FE_RESET_R                                       $16     !0, ->53
         24    > > FE_FETCH_R                                               $16, !3, ->53
   28    25    >   INIT_FCALL                                               'strtr'
         26        INIT_FCALL                                               'mb_strtolower'
         27        INIT_FCALL                                               'mb_substr'
         28        FETCH_OBJ_R                                      ~17     !3, 'title'
         29        SEND_VAL                                                 ~17
         30        SEND_VAL                                                 0
         31        SEND_VAL                                                 1
         32        SEND_VAL                                                 'UTF-8'
         33        DO_ICALL                                         $18     
         34        SEND_VAR                                                 $18
         35        SEND_VAL                                                 'UTF-8'
         36        DO_ICALL                                         $19     
         37        SEND_VAR                                                 $19
         38        SEND_VAR                                                 !2
         39        DO_ICALL                                         $20     
         40        ASSIGN                                                   !4, $20
   29    41        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !4
         42      > JMPZ                                                     ~22, ->48
   30    43    >   INIT_ARRAY                                       ~24     !4
         44        ADD_ARRAY_ELEMENT                                ~24     !3
         45        ASSIGN_DIM                                               !1, !4
         46        OP_DATA                                                  ~24
         47      > JMP                                                      ->52
   32    48    >   INIT_ARRAY                                       ~26     !4
         49        ADD_ARRAY_ELEMENT                                ~26     !3
         50        ASSIGN_DIM                                               !1, 'other'
         51        OP_DATA                                                  ~26
   27    52    > > JMP                                                      ->24
         53    >   FE_FREE                                                  $16
   36    54        INIT_FCALL                                               'var_export'
         55        SEND_VAR                                                 !1
         56        DO_ICALL                                                 
         57      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
199.49 ms | 1400 KiB | 27 Q