3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_map_userland_one($callback, array $one) { if ($callback) { // return array_map($callback, $one); echo "- with callback - apply\n"; $return = []; foreach ($one as $key => $value) { $return[$key] = $callback($value); } return $return; } else { // return array_map(function($value) { return $value; }, $one); echo "- without callback - return copy\n"; return $one; } } function array_map_userland_many($callback, array $many) { // for simplicity, assuming non-associative arrays all of the same size if ($callback) { // return array_map($callback, ...$many); echo "- with callback - apply using array of values\n"; $return = []; for ($i = 0; $i < count($many[0]); $i++) { $args = []; foreach ($many as $array) { $args[] = $array[$i]; } $return[$i] = $callback(...$args); } return $return; } else { // return array_map(function(...$values) { return $values; }, ...$many); echo "- without callback - use array of values\n"; $return = []; for ($i = 0; $i < count($many[0]); $i++) { $return[$i] = []; foreach ($many as $array) { $return[$i][] = $array[$i]; } } return $return; } } function array_map_userland($callback, ...$arrays) { if (count($arrays) == 1) { echo "- one array\n"; return array_map_userland_one($callback, $arrays[0]); } else { echo "- many arrays\n"; return array_map_userland_many($callback, $arrays); } } $two_item_array = [["abc", "def"], ["ghi", "jkl"]]; $one_item_array = [["abc", "def"]]; echo "Two arrays:\n"; print_r(array_map_userland(null, ...$two_item_array)); echo "One array:\n"; print_r(array_map_userland(null, ...$one_item_array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oZjhV
function name:  (null)
number of ops:  21
compiled vars:  !0 = $two_item_array, !1 = $one_item_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   ASSIGN                                                   !0, <array>
   62     1        ASSIGN                                                   !1, <array>
   64     2        ECHO                                                     'Two+arrays%3A%0A'
   65     3        INIT_FCALL                                               'print_r'
          4        INIT_FCALL                                               'array_map_userland'
          5        SEND_VAL                                                 null
          6        SEND_UNPACK                                              !0
          7        CHECK_UNDEF_ARGS                                         
          8        DO_FCALL                                      1  $4      
          9        SEND_VAR                                                 $4
         10        DO_ICALL                                                 
   66    11        ECHO                                                     'One+array%3A%0A'
   67    12        INIT_FCALL                                               'print_r'
         13        INIT_FCALL                                               'array_map_userland'
         14        SEND_VAL                                                 null
         15        SEND_UNPACK                                              !1
         16        CHECK_UNDEF_ARGS                                         
         17        DO_FCALL                                      1  $6      
         18        SEND_VAR                                                 $6
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function array_map_userland_one:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oZjhV
function name:  array_map_userland_one
number of ops:  20
compiled vars:  !0 = $callback, !1 = $one, !2 = $return, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2      > JMPZ                                                     !0, ->17
    7     3    >   ECHO                                                     '-+with+callback+-+apply%0A'
    8     4        ASSIGN                                                   !2, <array>
    9     5      > FE_RESET_R                                       $6      !1, ->14
          6    > > FE_FETCH_R                                       ~7      $6, !3, ->14
          7    >   ASSIGN                                                   !4, ~7
   10     8        INIT_DYNAMIC_CALL                                        !0
          9        SEND_VAR_EX                                              !3
         10        DO_FCALL                                      0  $10     
         11        ASSIGN_DIM                                               !2, !4
         12        OP_DATA                                                  $10
    9    13      > JMP                                                      ->6
         14    >   FE_FREE                                                  $6
   12    15      > RETURN                                                   !2
         16*       JMP                                                      ->19
   16    17    >   ECHO                                                     '-+without+callback+-+return+copy%0A'
   17    18      > RETURN                                                   !1
   19    19*     > RETURN                                                   null

End of function array_map_userland_one

Function array_map_userland_many:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 28
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 7
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 7
Branch analysis from position: 26
Branch analysis from position: 7
Branch analysis from position: 14
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 32
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 41
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 41
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 32
Branch analysis from position: 47
Branch analysis from position: 32
Branch analysis from position: 41
filename:       /in/oZjhV
function name:  array_map_userland_many
number of ops:  49
compiled vars:  !0 = $callback, !1 = $many, !2 = $return, !3 = $i, !4 = $args, !5 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     2      > JMPZ                                                     !0, ->28
   26     3    >   ECHO                                                     '-+with+callback+-+apply+using+array+of+values%0A'
   27     4        ASSIGN                                                   !2, <array>
   28     5        ASSIGN                                                   !3, 0
          6      > JMP                                                      ->22
   29     7    >   ASSIGN                                                   !4, <array>
   30     8      > FE_RESET_R                                       $9      !1, ->14
          9    > > FE_FETCH_R                                               $9, !5, ->14
   31    10    >   FETCH_DIM_R                                      ~11     !5, !3
         11        ASSIGN_DIM                                               !4
         12        OP_DATA                                                  ~11
   30    13      > JMP                                                      ->9
         14    >   FE_FREE                                                  $9
   33    15        INIT_DYNAMIC_CALL                                        !0
         16        SEND_UNPACK                                              !4
         17        CHECK_UNDEF_ARGS                                         
         18        DO_FCALL                                      1  $13     
         19        ASSIGN_DIM                                               !2, !3
         20        OP_DATA                                                  $13
   28    21        PRE_INC                                                  !3
         22    >   FETCH_DIM_R                                      ~15     !1, 0
         23        COUNT                                            ~16     ~15
         24        IS_SMALLER                                               !3, ~16
         25      > JMPNZ                                                    ~17, ->7
   35    26    > > RETURN                                                   !2
         27*       JMP                                                      ->48
   39    28    >   ECHO                                                     '-+without+callback+-+use+array+of+values%0A'
   40    29        ASSIGN                                                   !2, <array>
   41    30        ASSIGN                                                   !3, 0
         31      > JMP                                                      ->43
   42    32    >   ASSIGN_DIM                                               !2, !3
         33        OP_DATA                                                  <array>
   43    34      > FE_RESET_R                                       $21     !1, ->41
         35    > > FE_FETCH_R                                               $21, !5, ->41
   44    36    >   FETCH_DIM_R                                      ~24     !5, !3
         37        FETCH_DIM_W                                      $22     !2, !3
         38        ASSIGN_DIM                                               $22
         39        OP_DATA                                                  ~24
   43    40      > JMP                                                      ->35
         41    >   FE_FREE                                                  $21
   41    42        PRE_INC                                                  !3
         43    >   FETCH_DIM_R                                      ~26     !1, 0
         44        COUNT                                            ~27     ~26
         45        IS_SMALLER                                               !3, ~27
         46      > JMPNZ                                                    ~28, ->32
   47    47    > > RETURN                                                   !2
   49    48*     > RETURN                                                   null

End of function array_map_userland_many

Function array_map_userland:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oZjhV
function name:  array_map_userland
number of ops:  20
compiled vars:  !0 = $callback, !1 = $arrays
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
          1        RECV_VARIADIC                                    !1      
   52     2        COUNT                                            ~2      !1
          3        IS_EQUAL                                                 ~2, 1
          4      > JMPZ                                                     ~3, ->13
   53     5    >   ECHO                                                     '-+one+array%0A'
   54     6        INIT_FCALL                                               'array_map_userland_one'
          7        SEND_VAR                                                 !0
          8        FETCH_DIM_R                                      ~4      !1, 0
          9        SEND_VAL                                                 ~4
         10        DO_FCALL                                      0  $5      
         11      > RETURN                                                   $5
         12*       JMP                                                      ->19
   56    13    >   ECHO                                                     '-+many+arrays%0A'
   57    14        INIT_FCALL                                               'array_map_userland_many'
         15        SEND_VAR                                                 !0
         16        SEND_VAR                                                 !1
         17        DO_FCALL                                      0  $6      
         18      > RETURN                                                   $6
   59    19*     > RETURN                                                   null

End of function array_map_userland

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.16 ms | 1411 KiB | 19 Q