3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = [ (object)['title' => 'a test title'], (object)['title' => 'second title'], (object)['title' => 'Привет!'], (object)['title' => 'çà'], (object)['title' => '!Not a letter'] ]; // 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] = $item; } else { $groups['other'] = $item; } } var_export($groups);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 51
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 51
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 48
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
filename:       /in/AIAl1
function name:  (null)
number of ops:  56
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
    7     8        CAST                                          8  ~10     <array>
          9        ADD_ARRAY_ELEMENT                                ~6      ~10
    2    10        ASSIGN                                                   !0, ~6
   11    11        INIT_FCALL                                               'array_fill_keys'
         12        INIT_FCALL                                               'array_merge'
         13        INIT_FCALL                                               'range'
         14        SEND_VAL                                                 'a'
         15        SEND_VAL                                                 'z'
         16        DO_ICALL                                         $12     
         17        SEND_VAR                                                 $12
         18        SEND_VAL                                                 <array>
         19        DO_ICALL                                         $13     
         20        SEND_VAR                                                 $13
         21        SEND_VAL                                                 <array>
         22        DO_ICALL                                         $14     
         23        ASSIGN                                                   !1, $14
   16    24        ASSIGN                                                   !2, <array>
   28    25      > FE_RESET_R                                       $17     !0, ->51
         26    > > FE_FETCH_R                                               $17, !3, ->51
   29    27    >   INIT_FCALL                                               'strtr'
         28        INIT_FCALL                                               'mb_strtolower'
         29        INIT_FCALL                                               'mb_substr'
         30        FETCH_OBJ_R                                      ~18     !3, 'title'
         31        SEND_VAL                                                 ~18
         32        SEND_VAL                                                 0
         33        SEND_VAL                                                 1
         34        SEND_VAL                                                 'UTF-8'
         35        DO_ICALL                                         $19     
         36        SEND_VAR                                                 $19
         37        SEND_VAL                                                 'UTF-8'
         38        DO_ICALL                                         $20     
         39        SEND_VAR                                                 $20
         40        SEND_VAR                                                 !2
         41        DO_ICALL                                         $21     
         42        ASSIGN                                                   !4, $21
   30    43        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !4
         44      > JMPZ                                                     ~23, ->48
   31    45    >   ASSIGN_DIM                                               !1, !4
         46        OP_DATA                                                  !3
         47      > JMP                                                      ->50
   33    48    >   ASSIGN_DIM                                               !1, 'other'
         49        OP_DATA                                                  !3
   28    50    > > JMP                                                      ->26
         51    >   FE_FREE                                                  $17
   36    52        INIT_FCALL                                               'var_export'
         53        SEND_VAR                                                 !1
         54        DO_ICALL                                                 
         55      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.2 ms | 1400 KiB | 27 Q