3v4l.org

run code in 300+ PHP versions simultaneously
<?php $competence = json_decode('[ { "id": "21", "title": "blabla", "description": "blabla", "image": "blabla" }, { "id": "11", "title": "blabla", "description": "blabla", "image": "blabla" }, { "id": "26", "title": "blabla", "description": "blabla", "image": "blabla" } ]', true); $schedule = json_decode('[ { "id": "34", "parent_id": "21", "title": "blabla", "description": "blabla", "image": "blabla" }, { "id": "33", "parent_id": "21", "title": "blabla", "description": "blabla", "image": "blabla" }, { "id": "32", "parent_id": "11", "title": "blabla", "description": "blabla", "image": "blabla" }, { "id": "31", "parent_id": "26", "title": "blabla", "description": "blabla", "image": "blabla" } ]', true); foreach ($schedule as $s) { // find the parent_id in $competence if (($key = array_search($s['parent_id'], array_column($competence, 'id'))) !== false) { $competence[$key]['schedule'][] = $s; } } $response = array('competence' => $competence); echo json_encode($response, JSON_PRETTY_PRINT);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 29
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 29
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 28
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/5MeH4
function name:  (null)
number of ops:  38
compiled vars:  !0 = $competence, !1 = $schedule, !2 = $s, !3 = $key, !4 = $response
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'json_decode'
          1        SEND_VAL                                                 '%5B%0A++++%7B%0A++++++%22id%22%3A+%2221%22%2C%0A++++++%22title%22%3A+%22blabla%22%2C%0A++++++%22description%22%3A+%22blabla%22%2C%0A++++++%22image%22%3A+%22blabla%22%0A++++%7D%2C%0A++++%7B%0A++++++%22id%22%3A+%2211%22%2C%0A++++++%22title%22%3A+%22blabla%22%2C%0A++++++%22description%22%3A+%22blabla%22%2C%0A++++++%22image%22%3A+%22blabla%22%0A++++%7D%2C%0A++++%7B%0A++++++%22id%22%3A+%2226%22%2C%0A++++++%22title%22%3A+%22blabla%22%2C%0A++++++%22description%22%3A+%22blabla%22%2C%0A++++++%22image%22%3A+%22blabla%22%0A++++%7D%0A++%5D'
   22     2        SEND_VAL                                                 <true>
    3     3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !0, $5
   23     5        INIT_FCALL                                               'json_decode'
          6        SEND_VAL                                                 '%5B%0A++++%7B%0A++++++%22id%22%3A+%2234%22%2C%0A++++++%22parent_id%22%3A+%2221%22%2C%0A++++++%22title%22%3A+%22blabla%22%2C%0A++++++%22description%22%3A+%22blabla%22%2C%0A++++++%22image%22%3A+%22blabla%22%0A++++%7D%2C%0A++++%7B%0A++++++%22id%22%3A+%2233%22%2C%0A++++++%22parent_id%22%3A+%2221%22%2C%0A++++++%22title%22%3A+%22blabla%22%2C%0A++++++%22description%22%3A+%22blabla%22%2C%0A++++++%22image%22%3A+%22blabla%22%0A++++%7D%2C%0A++++%7B%0A++++++%22id%22%3A+%2232%22%2C%0A++++++%22parent_id%22%3A+%2211%22%2C%0A++++++%22title%22%3A+%22blabla%22%2C%0A++++++%22description%22%3A+%22blabla%22%2C%0A++++++%22image%22%3A+%22blabla%22%0A++++%7D%2C%0A++++%7B%0A++++++%22id%22%3A+%2231%22%2C%0A++++++%22parent_id%22%3A+%2226%22%2C%0A++++++%22title%22%3A+%22blabla%22%2C%0A++++++%22description%22%3A+%22blabla%22%2C%0A++++++%22image%22%3A+%22blabla%22%0A++++%7D%0A++%5D'
   52     7        SEND_VAL                                                 <true>
   23     8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !1, $7
   54    10      > FE_RESET_R                                       $9      !1, ->29
         11    > > FE_FETCH_R                                               $9, !2, ->29
   56    12    >   INIT_FCALL                                               'array_search'
         13        FETCH_DIM_R                                      ~10     !2, 'parent_id'
         14        SEND_VAL                                                 ~10
         15        INIT_FCALL                                               'array_column'
         16        SEND_VAR                                                 !0
         17        SEND_VAL                                                 'id'
         18        DO_ICALL                                         $11     
         19        SEND_VAR                                                 $11
         20        DO_ICALL                                         $12     
         21        ASSIGN                                           ~13     !3, $12
         22        TYPE_CHECK                                  1018          ~13
         23      > JMPZ                                                     ~14, ->28
   57    24    >   FETCH_DIM_W                                      $15     !0, !3
         25        FETCH_DIM_W                                      $16     $15, 'schedule'
         26        ASSIGN_DIM                                               $16
         27        OP_DATA                                                  !2
   54    28    > > JMP                                                      ->11
         29    >   FE_FREE                                                  $9
   60    30        INIT_ARRAY                                       ~18     !0, 'competence'
         31        ASSIGN                                                   !4, ~18
   62    32        INIT_FCALL                                               'json_encode'
         33        SEND_VAR                                                 !4
         34        SEND_VAL                                                 128
         35        DO_ICALL                                         $20     
         36        ECHO                                                     $20
         37      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.73 ms | 1008 KiB | 17 Q