3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = "{ \"Data 1\": { \"Text1\": \"Anything1\", \"Text2\": \"Anything2\" }, \"Data 2\": { \"2018-08-02\": { \"1.\": \"145\", \"2.\": \"258\" }, \"2018-08-03\": { \"1.\": \"428\", \"2.\": \"528\" }, \"2018-08-04\": { \"1.\": \"727\", \"2.\": \"514\" } } }"; $jsonDecoded = json_decode($json, true); foreach ($jsonDecoded['Data 2'] as $dateKey => $data) { //$values = ''; //foreach ($data as $datum) { // $values .= $datum . ','; //} $values = implode(',', $data); $statement = "INSERT INTO mytable (TheDate, Value1, Value2) VALUES ('{$dateKey}'," . $values . ");"; echo $statement . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 24
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 24
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/peLqP
function name:  (null)
number of ops:  26
compiled vars:  !0 = $json, !1 = $jsonDecoded, !2 = $data, !3 = $dateKey, !4 = $values, !5 = $statement
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%7B%0A++++%22Data+1%22%3A+%7B%0A++++++++%22Text1%22%3A+%22Anything1%22%2C%0A++++++++%22Text2%22%3A+%22Anything2%22%0A++++%7D%2C%0A++++%22Data+2%22%3A+%7B%0A++++++++%222018-08-02%22%3A+%7B%0A++++++++++++%221.%22%3A+%22145%22%2C%0A++++++++++++%222.%22%3A+%22258%22%0A++++++++%7D%2C%0A++++++++%222018-08-03%22%3A+%7B%0A++++++++++++%221.%22%3A+%22428%22%2C%0A++++++++++++%222.%22%3A+%22528%22%0A++++++++%7D%2C%0A++++++++%222018-08-04%22%3A+%7B%0A++++++++++++%221.%22%3A+%22727%22%2C%0A++++++++++++%222.%22%3A+%22514%22%0A++++++++%7D%0A++++%7D%0A%7D'
   23     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $7      
          5        ASSIGN                                                   !1, $7
   24     6        FETCH_DIM_R                                      ~9      !1, 'Data+2'
          7      > FE_RESET_R                                       $10     ~9, ->24
          8    > > FE_FETCH_R                                       ~11     $10, !2, ->24
          9    >   ASSIGN                                                   !3, ~11
   29    10        INIT_FCALL                                               'implode'
         11        SEND_VAL                                                 '%2C'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $13     
         14        ASSIGN                                                   !4, $13
   30    15        ROPE_INIT                                     3  ~16     'INSERT+INTO+mytable+%28TheDate%2C+Value1%2C+Value2%29+VALUES+%28%27'
         16        ROPE_ADD                                      1  ~16     ~16, !3
         17        ROPE_END                                      2  ~15     ~16, '%27%2C'
         18        CONCAT                                           ~18     ~15, !4
         19        CONCAT                                           ~19     ~18, '%29%3B'
         20        ASSIGN                                                   !5, ~19
   31    21        CONCAT                                           ~21     !5, '%0A'
         22        ECHO                                                     ~21
   24    23      > JMP                                                      ->8
         24    >   FE_FREE                                                  $10
   32    25      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.86 ms | 1000 KiB | 15 Q