3v4l.org

run code in 300+ PHP versions simultaneously
<?php $entities = [ ['name' => 'Answer', 'relations' => ['AnswerGroup']], ['name' => 'AnswerGroup', 'relations' => []], ['name' => 'Condition', 'relations' => ['Question']], ['name' => 'Notion', 'relations' => []], ['name' => 'Question', 'relations' => ['Theme', 'AnswerGroup', 'Notion']], ['name' => 'Theme', 'relations' => []], ]; function list_dependents($entity, $entities) { $sorted = array(); sort($entity['relations']); foreach ($entity['relations'] as $r) { $sorted = array_merge($sorted, list_dependents($entities[array_search($r, array_column($entities, 'name'))], $entities)); } $sorted = array_merge($sorted, array($entity['name'])); return $sorted; } $sorted = array(); foreach ($entities as $entity) { $sorted = array_merge($sorted, list_dependents($entity, $entities)); } $sorted = array_values(array_unique($sorted)); print_r($sorted);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/Nsq1t
function name:  (null)
number of ops:  26
compiled vars:  !0 = $entities, !1 = $sorted, !2 = $entity
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   19     1        ASSIGN                                                   !1, <array>
   20     2      > FE_RESET_R                                       $5      !0, ->14
          3    > > FE_FETCH_R                                               $5, !2, ->14
   21     4    >   INIT_FCALL                                               'array_merge'
          5        SEND_VAR                                                 !1
          6        INIT_FCALL                                               'list_dependents'
          7        SEND_VAR                                                 !2
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0  $6      
         10        SEND_VAR                                                 $6
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !1, $7
   20    13      > JMP                                                      ->3
         14    >   FE_FREE                                                  $5
   23    15        INIT_FCALL                                               'array_values'
         16        INIT_FCALL                                               'array_unique'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $9      
         19        SEND_VAR                                                 $9
         20        DO_ICALL                                         $10     
         21        ASSIGN                                                   !1, $10
   24    22        INIT_FCALL                                               'print_r'
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Function list_dependents:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 30
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 30
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/Nsq1t
function name:  list_dependents
number of ops:  40
compiled vars:  !0 = $entity, !1 = $entities, !2 = $sorted, !3 = $r
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2        ASSIGN                                                   !2, <array>
   12     3        INIT_FCALL                                               'sort'
          4        FETCH_DIM_W                                      $5      !0, 'relations'
          5        SEND_REF                                                 $5
          6        DO_ICALL                                                 
   13     7        FETCH_DIM_R                                      ~7      !0, 'relations'
          8      > FE_RESET_R                                       $8      ~7, ->30
          9    > > FE_FETCH_R                                               $8, !3, ->30
   14    10    >   INIT_FCALL                                               'array_merge'
         11        SEND_VAR                                                 !2
         12        INIT_FCALL_BY_NAME                                       'list_dependents'
         13        CHECK_FUNC_ARG                                           
         14        INIT_FCALL                                               'array_search'
         15        SEND_VAR                                                 !3
         16        INIT_FCALL                                               'array_column'
         17        SEND_VAR                                                 !1
         18        SEND_VAL                                                 'name'
         19        DO_ICALL                                         $9      
         20        SEND_VAR                                                 $9
         21        DO_ICALL                                         $10     
         22        FETCH_DIM_FUNC_ARG                               $11     !1, $10
         23        SEND_FUNC_ARG                                            $11
         24        SEND_VAR_EX                                              !1
         25        DO_FCALL                                      0  $12     
         26        SEND_VAR                                                 $12
         27        DO_ICALL                                         $13     
         28        ASSIGN                                                   !2, $13
   13    29      > JMP                                                      ->9
         30    >   FE_FREE                                                  $8
   16    31        INIT_FCALL                                               'array_merge'
         32        SEND_VAR                                                 !2
         33        FETCH_DIM_R                                      ~15     !0, 'name'
         34        INIT_ARRAY                                       ~16     ~15
         35        SEND_VAL                                                 ~16
         36        DO_ICALL                                         $17     
         37        ASSIGN                                                   !2, $17
   17    38      > RETURN                                                   !2
   18    39*     > RETURN                                                   null

End of function list_dependents

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.27 ms | 1024 KiB | 21 Q