3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ "id" => 2, "level" => 0, "email" => "bexcailimited1@gmail.com", ], [ [ "id" => 4, "level" => 1, "email" => "bexcailimited3@gmail.com", ], [ [ "id" => 5, "level" => 2, "email" => "bexcailimited4@gmail.com", ], [ [ "id" => 6, "level" => 3, "email" => "bexcailimited5@gmail.com", ], ], ], ], [ "id" => 3, "level" => 0, "email" => "bexcailimited2@gmail.com", ], [ "id" => 7, "level" => 0, "email" => "bexcaitest@gmail.com", ], [ [ "id" => 8, "level" => 1, "email" => "Test012@gmail.com", ], [ [ "id" => 9, "level" => 2, "email" => "test03@gmail.com", ], [ [ "id" => 10, "level" => 3, "email" => "test04@gmail.com", ], [ [ "id" => 11, "level" => 4, "email" => "test05@gmail.com", ], [ [ "id" => 12, "level" => 5, "email" => "test06@gmail.com", ], ], ], ], ], ], ]; function flattenList(array $array): array { $result = []; foreach ($array as $row) { array_push($result, ...array_is_list($row) ? flattenList($row) : [$row]); } return $result; } $flatten2d = flattenlist($array); usort($flatten2d, fn($a, $b) => $a['id'] <=> $b['id']); var_export($flatten2d);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PbuSla
function name:  (null)
number of ops:  14
compiled vars:  !0 = $array, !1 = $flatten2d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   86     1        INIT_FCALL                                               'flattenlist'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   87     5        INIT_FCALL                                               'usort'
          6        SEND_REF                                                 !1
          7        DECLARE_LAMBDA_FUNCTION                          ~5      [0]
          8        SEND_VAL                                                 ~5
          9        DO_ICALL                                                 
   88    10        INIT_FCALL                                               'var_export'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                                 
         13      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PbuSla
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   87     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        FETCH_DIM_R                                      ~2      !0, 'id'
          3        FETCH_DIM_R                                      ~3      !1, 'id'
          4        SPACESHIP                                        ~4      ~2, ~3
          5      > RETURN                                                   ~4
          6*     > RETURN                                                   null

End of Dynamic Function 0

Function flattenlist:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 21
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/PbuSla
function name:  flattenList
number of ops:  26
compiled vars:  !0 = $array, !1 = $result, !2 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   RECV                                             !0      
   79     1        ASSIGN                                                   !1, <array>
   80     2      > FE_RESET_R                                       $4      !0, ->21
          3    > > FE_FETCH_R                                               $4, !2, ->21
   81     4    >   INIT_FCALL                                               'array_push'
          5        SEND_REF                                                 !1
          6        INIT_FCALL                                               'array_is_list'
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                         $5      
          9      > JMPZ                                                     $5, ->15
         10    >   INIT_FCALL_BY_NAME                                       'flattenList'
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0  $6      
         13        QM_ASSIGN                                        ~7      $6
         14      > JMP                                                      ->17
         15    >   INIT_ARRAY                                       ~8      !2
         16        QM_ASSIGN                                        ~7      ~8
         17    >   SEND_UNPACK                                              ~7
         18        CHECK_UNDEF_ARGS                                         
         19        DO_ICALL                                                 
   80    20      > JMP                                                      ->3
         21    >   FE_FREE                                                  $4
   83    22        VERIFY_RETURN_TYPE                                       !1
         23      > RETURN                                                   !1
   84    24*       VERIFY_RETURN_TYPE                                       
         25*     > RETURN                                                   null

End of function flattenlist

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.78 ms | 1008 KiB | 18 Q