3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data_json = '{ "EXPORT": [ { "dates": "2019-07-01", "c_job": 12 }, { "dates": "2019-07-02", "c_job": 8 }, { "dates": "2019-07-04", "c_job": 11 } ], "IMPORT": [ { "dates": "2019-07-03", "c_job": 11 } ] }'; $blank_json = '[ { "dates": "2019-07-01", "c_job": 0 }, { "dates": "2019-07-02", "c_job": 0 }, { "dates": "2019-07-03", "c_job": 0 }, { "dates": "2019-07-04", "c_job": 0 } ]'; $data = json_decode($data_json, true); $blank = json_decode($blank_json, true); $datafinal = array(); foreach ($data as $key => $value) { foreach ($blank as $bkey => $bvalue) { if (($dkey = array_search($bvalue['dates'], array_column($value, 'dates'))) !== false) { $datafinal[$key][$bkey] = $value[$dkey]; } else { $datafinal[$key][$bkey] = $bvalue; } } } echo json_encode($datafinal, JSON_PRETTY_PRINT);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 42
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 42
Branch analysis from position: 15
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 40
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 40
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 40
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/j0u9h
function name:  (null)
number of ops:  49
compiled vars:  !0 = $data_json, !1 = $blank_json, !2 = $data, !3 = $blank, !4 = $datafinal, !5 = $value, !6 = $key, !7 = $bvalue, !8 = $bkey, !9 = $dkey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7B%0A++++%22EXPORT%22%3A+%5B%0A++++++%7B%0A++++++++%22dates%22%3A+%222019-07-01%22%2C%0A++++++++%22c_job%22%3A+12%0A++++++%7D%2C%0A++++++%7B%0A++++++++%22dates%22%3A+%222019-07-02%22%2C%0A++++++++%22c_job%22%3A+8%0A++++++%7D%2C%0A++++++%7B%0A++++++++%22dates%22%3A+%222019-07-04%22%2C%0A++++++++%22c_job%22%3A+11%0A++++++%7D%0A++++%5D%2C%0A++++%22IMPORT%22%3A+%5B%0A++++++%7B%0A++++++++%22dates%22%3A+%222019-07-03%22%2C%0A++++++++%22c_job%22%3A+11%0A++++++%7D%0A++++%5D%0A%7D'
   25     1        ASSIGN                                                   !1, '%5B%0A++++%7B%0A++++++%22dates%22%3A+%222019-07-01%22%2C%0A++++++%22c_job%22%3A+0%0A++++%7D%2C%0A++++%7B%0A++++++%22dates%22%3A+%222019-07-02%22%2C%0A++++++%22c_job%22%3A+0%0A++++%7D%2C%0A++++%7B%0A++++++%22dates%22%3A+%222019-07-03%22%2C%0A++++++%22c_job%22%3A+0%0A++++%7D%2C%0A++++%7B%0A++++++%22dates%22%3A+%222019-07-04%22%2C%0A++++++%22c_job%22%3A+0%0A++++%7D%0A++%5D'
   43     2        INIT_FCALL                                               'json_decode'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $12     
          6        ASSIGN                                                   !2, $12
   44     7        INIT_FCALL                                               'json_decode'
          8        SEND_VAR                                                 !1
          9        SEND_VAL                                                 <true>
         10        DO_ICALL                                         $14     
         11        ASSIGN                                                   !3, $14
   46    12        ASSIGN                                                   !4, <array>
   47    13      > FE_RESET_R                                       $17     !2, ->42
         14    > > FE_FETCH_R                                       ~18     $17, !5, ->42
         15    >   ASSIGN                                                   !6, ~18
   48    16      > FE_RESET_R                                       $20     !3, ->40
         17    > > FE_FETCH_R                                       ~21     $20, !7, ->40
         18    >   ASSIGN                                                   !8, ~21
   49    19        INIT_FCALL                                               'array_search'
         20        FETCH_DIM_R                                      ~23     !7, 'dates'
         21        SEND_VAL                                                 ~23
         22        INIT_FCALL                                               'array_column'
         23        SEND_VAR                                                 !5
         24        SEND_VAL                                                 'dates'
         25        DO_ICALL                                         $24     
         26        SEND_VAR                                                 $24
         27        DO_ICALL                                         $25     
         28        ASSIGN                                           ~26     !9, $25
         29        TYPE_CHECK                                  1018          ~26
         30      > JMPZ                                                     ~27, ->36
   50    31    >   FETCH_DIM_R                                      ~30     !5, !9
         32        FETCH_DIM_W                                      $28     !4, !6
         33        ASSIGN_DIM                                               $28, !8
         34        OP_DATA                                                  ~30
   49    35      > JMP                                                      ->39
   53    36    >   FETCH_DIM_W                                      $31     !4, !6
         37        ASSIGN_DIM                                               $31, !8
         38        OP_DATA                                                  !7
   48    39    > > JMP                                                      ->17
         40    >   FE_FREE                                                  $20
   47    41      > JMP                                                      ->14
         42    >   FE_FREE                                                  $17
   57    43        INIT_FCALL                                               'json_encode'
         44        SEND_VAR                                                 !4
         45        SEND_VAL                                                 128
         46        DO_ICALL                                         $33     
         47        ECHO                                                     $33
         48      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.05 ms | 960 KiB | 17 Q