3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Arr { public static function dot($array, $prepend = '') { $output = array(); foreach($array as $k => $v) { if(is_array($v)) { $output = array_merge($output, static::dot($v, $prepend . $k . '.')); } else { $output[$prepend . $k] = $v; } } return $output; } public static function dotRev($array, $count = 1, $keySearchPrepend = '') { $output = array(); foreach($array as $ks => $v) { $ks2 = explode('.', $ks); $k = static::lastV($ks2); if(count($ks2) > $count) { $output[$k] = static::dotRev($array, $count + 1, $keySearchPrepend . $k . '.'); } else { if($ks !== $keySearchPrepend . $k) continue; $output[$k] = $v; } } } public static function firstV($array) { if(count($array) < 1) return null; $values = array_values($array); return $values[0]; } public static function lastV($array) { if(count($array) < 1) return null; $values = array_values($array); return $values[(count($values) - 1)]; } public static function firstK($array) { if(count($array) < 1) return null; $values = array_keys($array); return $values[0]; } public static function lastK($array) { if(count($array) < 1) return null; $values = array_keys($array); return $values[(count($values) - 1)]; } } var_export(Arr::dotRev(array ( 'app.config.enviornments.development.0' => 'development.meta.php', 'app.config.enviornments.maintanence.0' => 'maintanence.meta.php', 'app.config.enviornments.production.0' => 'production.meta.php', 'app.config.subdomains.blog.0' => 'blog.meta.php', 'app.config.subdomains.files.0' => 'files.meta.php', 'app.config.subdomains.i.0' => 'i.meta.php', 'app.config.subdomains.www.0' => 'paths.php', 'app.config.subdomains.www.1' => 'www.meta.php', 'app.config.0' => 'app.php', 'app.config.1' => 'database.php', 'app.config.2' => 'paths.php', 'app.0' => 'routing.php', 'bootstrap.0' => 'autoload.php', 'engine.Assets.0' => 'Asset.php', 'engine.Assets.1' => 'Assets.php', 'engine.Console.0' => 'Factory.php', 'engine.Console.1' => 'Manager.php', 'engine.Core.App.0' => 'Application.php', 'engine.Core.App.1' => 'Enviornments.php', 'engine.Core.Errors.0' => 'Error.php', 'engine.Core.Errors.1' => 'ErrorMessages.php', 'engine.Core.Errors.2' => 'Errors.php', 'engine.Core.Settings.0' => 'Factory.php', 'engine.Core.Settings.1' => 'Settings.php', 'engine.Core.0' => 'Constants.php', 'engine.Core.1' => 'Functions.php', 'engine.Database.QueryBuilder.0' => 'Builder.php', 'engine.Database.QueryBuilder.1' => 'Factory.php', 'engine.Database.0' => 'Database.php', 'engine.Filesystem.Exception.0' => 'FileNotFound.php', 'engine.Filesystem.Exception.1' => 'Filesytem.php', 'engine.Filesystem.0' => 'Directory.php', 'engine.Filesystem.1' => 'File.php', 'engine.Filesystem.2' => 'FilePartInterface.php', 'engine.Filesystem.3' => 'Filesystem.php', 'engine.Html.Table.0' => 'AbstractTablePart.php', 'engine.Html.Table.1' => 'TableBody.php', 'engine.Html.Table.2' => 'TableBuilder.php', 'engine.Html.Table.3' => 'TableFooter.php', 'engine.Html.Table.4' => 'TableHeader.php', 'engine.Html.Table.5' => 'TableRow.php', 'engine.Html.0' => 'Assets.php', 'engine.Html.1' => 'HtmlFactory.php', 'engine.Html.2' => 'HtmlTag.php', 'engine.Html.3' => 'HtmlTags.php', 'engine.Http.Request.0' => 'Factory.php', 'engine.Http.Request.1' => 'HttpRequest.php', 'engine.Http.Request.2' => 'HttpResponse.php', 'engine.Http.Route.0' => 'Router.php', 'engine.Logger.Loggers.0' => 'ConsoleLogger.php', 'engine.Logger.Loggers.1' => 'DevWebLogger.php', 'engine.Logger.Loggers.2' => 'NullLogger.php', 'engine.Logger.Loggers.3' => 'StandardLogger.php', 'engine.Logger.Loggers.4' => 'WebLogger.php', 'engine.Logger.0' => 'AbstractLogger.php', 'engine.Logger.1' => 'LoggerInterface.php', 'engine.Logger.2' => 'LoggerLevel.php', 'engine.Request.0' => 'Factory.php', 'engine.Request.1' => 'Request.php', 'engine.Support.DataTypes.0' => 'Arr.php', 'engine.Support.Interfaces.0' => 'Arrayable.php', 'engine.Support.Interfaces.1' => 'Renderable.php', 'engine.Support.0' => 'ArrayUtils.php', 'engine.Support.1' => 'Constants.php', 'engine.Support.2' => 'DataUtils.php', 'engine.Support.3' => 'Factory.php', 'engine.Support.4' => 'StaticInstance.php', 'engine.Support.5' => 'StringUtils.php', 'engine.Support.6' => 'Utilities.php', 'engine.Views.0' => 'AbstractTemplate.php', 'engine.Views.1' => 'CompiledTemplate.php', 'engine.Views.2' => 'NativeTemplate.php', 'engine.Views.3' => 'TemplatingErrorExcpetion.php', 'engine.Views.4' => 'ViewNotFoundException.php', 'engine.Widgets.FileStructure.0' => 'Factory.php', 'engine.Widgets.FileStructure.1' => 'FileStructure.php', 'public.www.0' => 'index.php', 0 => '.htaccess', 1 => 'debug.txt', 2 => 'debug2.txt', 3 => 'debug3.txt', 4 => 'output.txt', 5 => 'test.php', )));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OgjXg
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   INIT_FCALL                                               'var_export'
          1        INIT_STATIC_METHOD_CALL                                  'Arr', 'dotRev'
   64     2        SEND_VAL                                                 <array>
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
  147     6      > RETURN                                                   1

Class Arr:
Function dot:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 24
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 20
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/OgjXg
function name:  dot
number of ops:  27
compiled vars:  !0 = $array, !1 = $prepend, !2 = $output, !3 = $v, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      ''
    5     2        ASSIGN                                                   !2, <array>
    7     3      > FE_RESET_R                                       $6      !0, ->24
          4    > > FE_FETCH_R                                       ~7      $6, !3, ->24
          5    >   ASSIGN                                                   !4, ~7
    8     6        TYPE_CHECK                                  128          !3
          7      > JMPZ                                                     ~9, ->20
    9     8    >   INIT_FCALL                                               'array_merge'
          9        SEND_VAR                                                 !2
         10        INIT_STATIC_METHOD_CALL                                  'dot'
         11        SEND_VAR_EX                                              !3
         12        CONCAT                                           ~10     !1, !4
         13        CONCAT                                           ~11     ~10, '.'
         14        SEND_VAL_EX                                              ~11
         15        DO_FCALL                                      0  $12     
         16        SEND_VAR                                                 $12
         17        DO_ICALL                                         $13     
         18        ASSIGN                                                   !2, $13
         19      > JMP                                                      ->23
   11    20    >   CONCAT                                           ~15     !1, !4
         21        ASSIGN_DIM                                               !2, ~15
         22        OP_DATA                                                  !3
    7    23    > > JMP                                                      ->4
         24    >   FE_FREE                                                  $6
   15    25      > RETURN                                                   !2
   16    26*     > RETURN                                                   null

End of function dot

Function dotrev:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 37
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 37
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 30
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/OgjXg
function name:  dotRev
number of ops:  39
compiled vars:  !0 = $array, !1 = $count, !2 = $keySearchPrepend, !3 = $output, !4 = $v, !5 = $ks, !6 = $ks2, !7 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1
          2        RECV_INIT                                        !2      ''
   19     3        ASSIGN                                                   !3, <array>
   21     4      > FE_RESET_R                                       $9      !0, ->37
          5    > > FE_FETCH_R                                       ~10     $9, !4, ->37
          6    >   ASSIGN                                                   !5, ~10
   22     7        INIT_FCALL                                               'explode'
          8        SEND_VAL                                                 '.'
          9        SEND_VAR                                                 !5
         10        DO_ICALL                                         $12     
         11        ASSIGN                                                   !6, $12
   23    12        INIT_STATIC_METHOD_CALL                                  'lastV'
         13        SEND_VAR_EX                                              !6
         14        DO_FCALL                                      0  $14     
         15        ASSIGN                                                   !7, $14
   24    16        COUNT                                            ~16     !6
         17        IS_SMALLER                                               !1, ~16
         18      > JMPZ                                                     ~17, ->30
   25    19    >   INIT_STATIC_METHOD_CALL                                  'dotRev'
         20        SEND_VAR_EX                                              !0
         21        ADD                                              ~19     !1, 1
         22        SEND_VAL_EX                                              ~19
         23        CONCAT                                           ~20     !2, !7
         24        CONCAT                                           ~21     ~20, '.'
         25        SEND_VAL_EX                                              ~21
         26        DO_FCALL                                      0  $22     
         27        ASSIGN_DIM                                               !3, !7
         28        OP_DATA                                                  $22
         29      > JMP                                                      ->36
   27    30    >   CONCAT                                           ~23     !2, !7
         31        IS_NOT_IDENTICAL                                         !5, ~23
         32      > JMPZ                                                     ~24, ->34
         33    > > JMP                                                      ->5
   29    34    >   ASSIGN_DIM                                               !3, !7
         35        OP_DATA                                                  !4
   21    36    > > JMP                                                      ->5
         37    >   FE_FREE                                                  $9
   32    38      > RETURN                                                   null

End of function dotrev

Function firstv:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OgjXg
function name:  firstV
number of ops:  12
compiled vars:  !0 = $array, !1 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        COUNT                                            ~2      !0
          2        IS_SMALLER                                               ~2, 1
          3      > JMPZ                                                     ~3, ->5
          4    > > RETURN                                                   null
   37     5    >   INIT_FCALL                                               'array_values'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !1, $4
   38     9        FETCH_DIM_R                                      ~6      !1, 0
         10      > RETURN                                                   ~6
   39    11*     > RETURN                                                   null

End of function firstv

Function lastv:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OgjXg
function name:  lastV
number of ops:  14
compiled vars:  !0 = $array, !1 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   42     1        COUNT                                            ~2      !0
          2        IS_SMALLER                                               ~2, 1
          3      > JMPZ                                                     ~3, ->5
          4    > > RETURN                                                   null
   44     5    >   INIT_FCALL                                               'array_values'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !1, $4
   45     9        COUNT                                            ~6      !1
         10        SUB                                              ~7      ~6, 1
         11        FETCH_DIM_R                                      ~8      !1, ~7
         12      > RETURN                                                   ~8
   46    13*     > RETURN                                                   null

End of function lastv

Function firstk:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OgjXg
function name:  firstK
number of ops:  12
compiled vars:  !0 = $array, !1 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
   49     1        COUNT                                            ~2      !0
          2        IS_SMALLER                                               ~2, 1
          3      > JMPZ                                                     ~3, ->5
          4    > > RETURN                                                   null
   51     5    >   INIT_FCALL                                               'array_keys'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !1, $4
   52     9        FETCH_DIM_R                                      ~6      !1, 0
         10      > RETURN                                                   ~6
   53    11*     > RETURN                                                   null

End of function firstk

Function lastk:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OgjXg
function name:  lastK
number of ops:  14
compiled vars:  !0 = $array, !1 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
   56     1        COUNT                                            ~2      !0
          2        IS_SMALLER                                               ~2, 1
          3      > JMPZ                                                     ~3, ->5
          4    > > RETURN                                                   null
   58     5    >   INIT_FCALL                                               'array_keys'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !1, $4
   59     9        COUNT                                            ~6      !1
         10        SUB                                              ~7      ~6, 1
         11        FETCH_DIM_R                                      ~8      !1, ~7
         12      > RETURN                                                   ~8
   60    13*     > RETURN                                                   null

End of function lastk

End of class Arr.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.21 ms | 1408 KiB | 23 Q