3v4l.org

run code in 300+ PHP versions simultaneously
<?php $content = json_decode('{"creditor_trans_id":"655354-1","invoices":[{"id":"111333","date_created":"2015-06-02T00:00:00","payment_due":"2015-06-15T00:00:00","currency":"PLN","total":"45000","left_to_pay":"40000"}],"attachments":[{"id":"586a84aa-1b41-11e5-91d6-0cc47a41af63","name":"test324794_256.bmp","size":10002,"thumbnailUrl":null,"type":"image\/x-ms-bmp","expires":"2015-06-26T01:51:57+02:00","_links":{"self":{"href":"http:\/\/api.transinkasso.eu\/api\/rest\/debt-attachment\/586a84aa-1b41-11e5-91d6-0cc47a41af63"}}},{"id":"586b2f8c-1b41-11e5-91d6-0cc47a41af63","name":"tif_test.tif","size":26144,"thumbnailUrl":null,"type":"image\/tiff","expires":"2015-06-26T01:51:57+02:00","_links":{"self":{"href":"http:\/\/api.transinkasso.eu\/api\/rest\/debt-attachment\/586b2f8c-1b41-11e5-91d6-0cc47a41af63"}}},{"id":"586b9033-1b41-11e5-91d6-0cc47a41af63","name":"test324794.bmp","size":26438,"thumbnailUrl":null,"type":"image\/x-ms-bmp","expires":"2015-06-26T01:51:57+02:00","_links":{"self":{"href":"http:\/\/api.transinkasso.eu\/api\/rest\/debt-attachment\/586b9033-1b41-11e5-91d6-0cc47a41af63"}}},{"id":"586d3a17-1b41-11e5-91d6-0cc47a41af63","name":"test324794.png","size":24989,"thumbnailUrl":null,"type":"image\/png","expires":"2015-06-26T01:51:57+02:00","_links":{"self":{"href":"http:\/\/api.transinkasso.eu\/api\/rest\/debt-attachment\/586d3a17-1b41-11e5-91d6-0cc47a41af63"}}},{"id":"5879e073-1b41-11e5-91d6-0cc47a41af63","name":"Rotating_earth_(large).gif","size":316029,"thumbnailUrl":null,"type":"image\/gif","expires":"2015-06-26T01:51:57+02:00","_links":{"self":{"href":"http:\/\/api.transinkasso.eu\/api\/rest\/debt-attachment\/5879e073-1b41-11e5-91d6-0cc47a41af63"}}}],"debtor_company":{"country":"PL","vat_id":"1112223334","name":"RST test12 15 51","email":"test1@truckx.eu","phone":"1234567","city":"Wroc\u0142aw","postal_code":"21-222","address":"chabrowa 4 kilka plikow 5 do 1mb"}} | completed | 2015-06-25 15:52:16 | 2015-06-25 15:52:16 || 41 | {"creditor_trans_id":"655354-1","invoices":[{"id":"1111444","date_created":"2015-06-01T00:00:00","payment_due":"2015-06-22T00:00:00","currency":"PLN","total":"55555","left_to_pay":"9000"},{"id":"2222555","date_created":"2015-06-02T00:00:00","payment_due":"2015-06-23T00:00:00","currency":"PLN","total":"600","left_to_pay":"60"}],"attachments":[],"debtor_company":{"country":"PL","vat_id":"1112223334","name":"RST test12 15 52","email":"test1@truckx.eu","phone":"1234567","city":"Wroclaw","postal_code":"21-222","address":"chabrowa 4 kilka faktur bez plikow 1 waluta"}}', true); $data = [ 'transId' => $content['creditor_trans_id'], 'debtorCompany' => [ 'nip' => $content['debtor_company']['vat_id'], 'zipCode' => $content['debtor_company']['postal_code'], 'city' => $content['debtor_company']['city'], 'name' => $content['debtor_company']['name'], 'address' => $content['debtor_company']['address'], 'countryCode' => $content['debtor_company']['country'], 'email' => empty($content['debtor_company']['email']) ? null : $content['debtor_company']['email'], 'phone' => empty($content['debtor_company']['phone']) ? null : preg_replace('/[^0-9]/', '', $content['debtor_company']['phone']), ], 'invoices' => $content['invoices'], 'attachments' => $content['attachments'], ]; $content = $data; $content['debts'] = []; foreach ($content['invoices'] as $invoice) { $key = false; if ($content['debts']) { $key = array_search($invoice['currency'], array_column($content['debts'], 'currency')); } if ($key !== false) { $content['debts'][$key]['total'] = bcadd($content['debts'][$key]['total'], $invoice['total'], 2); $content['debts'][$key]['invoices'][] = $invoice; } else { $content['debts'][] = [ 'id' => 0, 'debtReportId' => 0, 'currency' => $invoice['currency'], 'total' => $invoice['total'], 'dateCreated' => null, 'invoices' => [ [ 'id' => 0, 'number' => $invoice['id'], 'issueDate' => $invoice['date_created'], 'paymentDate' => $invoice['payment_due'], 'total' => $invoice['total'], 'leftToPay' => $invoice['left_to_pay'], ] ], ]; } } unset($content['invoices']); echo json_encode($content);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
2 jumps found. (Code = 77) Position 1 = 59, Position 2 = 121
Branch analysis from position: 59
2 jumps found. (Code = 78) Position 1 = 60, Position 2 = 121
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 74
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 97
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 120
Branch analysis from position: 120
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 97
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 74
Branch analysis from position: 121
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 121
Branch analysis from position: 39
2 jumps found. (Code = 77) Position 1 = 59, Position 2 = 121
Branch analysis from position: 59
Branch analysis from position: 121
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
Branch analysis from position: 39
filename:       /in/TGRpT
function name:  (null)
number of ops:  128
compiled vars:  !0 = $content, !1 = $data, !2 = $invoice, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'json_decode'
          1        SEND_VAL                                                 '%7B%22creditor_trans_id%22%3A%22655354-1%22%2C%22invoices%22%3A%5B%7B%22id%22%3A%22111333%22%2C%22date_created%22%3A%222015-06-02T00%3A00%3A00%22%2C%22payment_due%22%3A%222015-06-15T00%3A00%3A00%22%2C%22currency%22%3A%22PLN%22%2C%22total%22%3A%2245000%22%2C%22left_to_pay%22%3A%2240000%22%7D%5D%2C%22attachments%22%3A%5B%7B%22id%22%3A%22586a84aa-1b41-11e5-91d6-0cc47a41af63%22%2C%22name%22%3A%22test324794_256.bmp%22%2C%22size%22%3A10002%2C%22thumbnailUrl%22%3Anull%2C%22type%22%3A%22image%5C%2Fx-ms-bmp%22%2C%22expires%22%3A%222015-06-26T01%3A51%3A57%2B02%3A00%22%2C%22_links%22%3A%7B%22self%22%3A%7B%22href%22%3A%22http%3A%5C%2F%5C%2Fapi.transinkasso.eu%5C%2Fapi%5C%2Frest%5C%2Fdebt-attachment%5C%2F586a84aa-1b41-11e5-91d6-0cc47a41af63%22%7D%7D%7D%2C%7B%22id%22%3A%22586b2f8c-1b41-11e5-91d6-0cc47a41af63%22%2C%22name%22%3A%22tif_test.tif%22%2C%22size%22%3A26144%2C%22thumbnailUrl%22%3Anull%2C%22type%22%3A%22image%5C%2Ftiff%22%2C%22expires%22%3A%222015-06-26T01%3A51%3A57%2B02%3A00%22%2C%22_links%22%3A%7B%22self%22%3A%7B%22href%22%3A%22http%3A%5C%2F%5C%2Fapi.transinkasso.eu%5C%2Fapi%5C%2Frest%5C%2Fdebt-attachment%5C%2F586b2f8c-1b41-11e5-91d6-0cc47a41af63%22%7D%7D%7D%2C%7B%22id%22%3A%22586b9033-1b41-11e5-91d6-0cc47a41af63%22%2C%22name%22%3A%22test324794.bmp%22%2C%22size%22%3A26438%2C%22thumbnailUrl%22%3Anull%2C%22type%22%3A%22image%5C%2Fx-ms-bmp%22%2C%22expires%22%3A%222015-06-26T01%3A51%3A57%2B02%3A00%22%2C%22_links%22%3A%7B%22self%22%3A%7B%22href%22%3A%22http%3A%5C%2F%5C%2Fapi.transinkasso.eu%5C%2Fapi%5C%2Frest%5C%2Fdebt-attachment%5C%2F586b9033-1b41-11e5-91d6-0cc47a41af63%22%7D%7D%7D%2C%7B%22id%22%3A%22586d3a17-1b41-11e5-91d6-0cc47a41af63%22%2C%22name%22%3A%22test324794.png%22%2C%22size%22%3A24989%2C%22thumbnailUrl%22%3Anull%2C%22type%22%3A%22image%5C%2Fpng%22%2C%22expires%22%3A%222015-06-26T01%3A51%3A57%2B02%3A00%22%2C%22_links%22%3A%7B%22self%22%3A%7B%22href%22%3A%22http%3A%5C%2F%5C%2Fapi.transinkasso.eu%5C%2Fapi%5C%2Frest%5C%2Fdebt-attachment%5C%2F586d3a17-1b41-11e5-91d6-0cc47a41af63%22%7D%7D%7D%2C%7B%22id%22%3A%225879e073-1b41-11e5-91d6-0cc47a41af63%22%2C%22name%22%3A%22Rotating_earth_%28large%29.gif%22%2C%22size%22%3A316029%2C%22thumbnailUrl%22%3Anull%2C%22type%22%3A%22image%5C%2Fgif%22%2C%22expires%22%3A%222015-06-26T01%3A51%3A57%2B02%3A00%22%2C%22_links%22%3A%7B%22self%22%3A%7B%22href%22%3A%22http%3A%5C%2F%5C%2Fapi.transinkasso.eu%5C%2Fapi%5C%2Frest%5C%2Fdebt-attachment%5C%2F5879e073-1b41-11e5-91d6-0cc47a41af63%22%7D%7D%7D%5D%2C%22debtor_company%22%3A%7B%22country%22%3A%22PL%22%2C%22vat_id%22%3A%221112223334%22%2C%22name%22%3A%22RST+test12+15+51%22%2C%22email%22%3A%22test1%40truckx.eu%22%2C%22phone%22%3A%221234567%22%2C%22city%22%3A%22Wroc%5Cu0142aw%22%2C%22postal_code%22%3A%2221-222%22%2C%22address%22%3A%22chabrowa+4+kilka+plikow+5+do+1mb%22%7D%7D+%7C+completed+%7C+2015-06-25+15%3A52%3A16+%7C+2015-06-25+15%3A52%3A16+%7C%7C+41+%7C+%7B%22creditor_trans_id%22%3A%22655354-1%22%2C%22invoices%22%3A%5B%7B%22id%22%3A%221111444%22%2C%22date_created%22%3A%222015-06-01T00%3A00%3A00%22%2C%22payment_due%22%3A%222015-06-22T00%3A00%3A00%22%2C%22currency%22%3A%22PLN%22%2C%22total%22%3A%2255555%22%2C%22left_to_pay%22%3A%229000%22%7D%2C%7B%22id%22%3A%222222555%22%2C%22date_created%22%3A%222015-06-02T00%3A00%3A00%22%2C%22payment_due%22%3A%222015-06-23T00%3A00%3A00%22%2C%22currency%22%3A%22PLN%22%2C%22total%22%3A%22600%22%2C%22left_to_pay%22%3A%2260%22%7D%5D%2C%22attachments%22%3A%5B%5D%2C%22debtor_company%22%3A%7B%22country%22%3A%22PL%22%2C%22vat_id%22%3A%221112223334%22%2C%22name%22%3A%22RST+test12+15+52%22%2C%22email%22%3A%22test1%40truckx.eu%22%2C%22phone%22%3A%221234567%22%2C%22city%22%3A%22Wroclaw%22%2C%22postal_code%22%3A%2221-222%22%2C%22address%22%3A%22chabrowa+4+kilka+faktur+bez+plikow+1+waluta%22%7D%7D'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !0, $4
    6     5        FETCH_DIM_R                                      ~6      !0, 'creditor_trans_id'
          6        INIT_ARRAY                                       ~7      ~6, 'transId'
    8     7        FETCH_DIM_R                                      ~8      !0, 'debtor_company'
          8        FETCH_DIM_R                                      ~9      ~8, 'vat_id'
          9        INIT_ARRAY                                       ~10     ~9, 'nip'
    9    10        FETCH_DIM_R                                      ~11     !0, 'debtor_company'
         11        FETCH_DIM_R                                      ~12     ~11, 'postal_code'
         12        ADD_ARRAY_ELEMENT                                ~10     ~12, 'zipCode'
   10    13        FETCH_DIM_R                                      ~13     !0, 'debtor_company'
         14        FETCH_DIM_R                                      ~14     ~13, 'city'
         15        ADD_ARRAY_ELEMENT                                ~10     ~14, 'city'
   11    16        FETCH_DIM_R                                      ~15     !0, 'debtor_company'
         17        FETCH_DIM_R                                      ~16     ~15, 'name'
         18        ADD_ARRAY_ELEMENT                                ~10     ~16, 'name'
   12    19        FETCH_DIM_R                                      ~17     !0, 'debtor_company'
         20        FETCH_DIM_R                                      ~18     ~17, 'address'
         21        ADD_ARRAY_ELEMENT                                ~10     ~18, 'address'
   13    22        FETCH_DIM_R                                      ~19     !0, 'debtor_company'
         23        FETCH_DIM_R                                      ~20     ~19, 'country'
         24        ADD_ARRAY_ELEMENT                                ~10     ~20, 'countryCode'
   14    25        FETCH_DIM_IS                                     ~21     !0, 'debtor_company'
         26        ISSET_ISEMPTY_DIM_OBJ                         1          ~21, 'email'
         27      > JMPZ                                                     ~22, ->30
    6    28    >   QM_ASSIGN                                        ~23     null
         29      > JMP                                                      ->33
   14    30    >   FETCH_DIM_R                                      ~24     !0, 'debtor_company'
         31        FETCH_DIM_R                                      ~25     ~24, 'email'
         32        QM_ASSIGN                                        ~23     ~25
         33    >   ADD_ARRAY_ELEMENT                                ~10     ~23, 'email'
   15    34        FETCH_DIM_IS                                     ~26     !0, 'debtor_company'
         35        ISSET_ISEMPTY_DIM_OBJ                         1          ~26, 'phone'
         36      > JMPZ                                                     ~27, ->39
    6    37    >   QM_ASSIGN                                        ~28     null
         38      > JMP                                                      ->47
   15    39    >   INIT_FCALL                                               'preg_replace'
         40        SEND_VAL                                                 '%2F%5B%5E0-9%5D%2F'
         41        SEND_VAL                                                 ''
   16    42        FETCH_DIM_R                                      ~29     !0, 'debtor_company'
         43        FETCH_DIM_R                                      ~30     ~29, 'phone'
         44        SEND_VAL                                                 ~30
         45        DO_ICALL                                         $31     
         46        QM_ASSIGN                                        ~28     $31
         47    >   ADD_ARRAY_ELEMENT                                ~10     ~28, 'phone'
         48        ADD_ARRAY_ELEMENT                                ~7      ~10, 'debtorCompany'
   18    49        FETCH_DIM_R                                      ~32     !0, 'invoices'
         50        ADD_ARRAY_ELEMENT                                ~7      ~32, 'invoices'
   19    51        FETCH_DIM_R                                      ~33     !0, 'attachments'
         52        ADD_ARRAY_ELEMENT                                ~7      ~33, 'attachments'
    5    53        ASSIGN                                                   !1, ~7
   22    54        ASSIGN                                                   !0, !1
   24    55        ASSIGN_DIM                                               !0, 'debts'
         56        OP_DATA                                                  <array>
   26    57        FETCH_DIM_R                                      ~37     !0, 'invoices'
         58      > FE_RESET_R                                       $38     ~37, ->121
         59    > > FE_FETCH_R                                               $38, !2, ->121
   27    60    >   ASSIGN                                                   !3, <false>
   29    61        FETCH_DIM_R                                      ~40     !0, 'debts'
         62      > JMPZ                                                     ~40, ->74
   30    63    >   INIT_FCALL                                               'array_search'
         64        FETCH_DIM_R                                      ~41     !2, 'currency'
         65        SEND_VAL                                                 ~41
         66        INIT_FCALL                                               'array_column'
         67        FETCH_DIM_R                                      ~42     !0, 'debts'
         68        SEND_VAL                                                 ~42
         69        SEND_VAL                                                 'currency'
         70        DO_ICALL                                         $43     
         71        SEND_VAR                                                 $43
         72        DO_ICALL                                         $44     
         73        ASSIGN                                                   !3, $44
   33    74    >   TYPE_CHECK                                  1018          !3
         75      > JMPZ                                                     ~46, ->97
   34    76    >   INIT_FCALL_BY_NAME                                       'bcadd'
         77        CHECK_FUNC_ARG                                           
         78        FETCH_DIM_FUNC_ARG                               $50     !0, 'debts'
         79        FETCH_DIM_FUNC_ARG                               $51     $50, !3
         80        FETCH_DIM_FUNC_ARG                               $52     $51, 'total'
         81        SEND_FUNC_ARG                                            $52
         82        CHECK_FUNC_ARG                                           
         83        FETCH_DIM_FUNC_ARG                               $53     !2, 'total'
         84        SEND_FUNC_ARG                                            $53
         85        SEND_VAL_EX                                              2
         86        DO_FCALL                                      0  $54     
         87        FETCH_DIM_W                                      $47     !0, 'debts'
         88        FETCH_DIM_W                                      $48     $47, !3
         89        ASSIGN_DIM                                               $48, 'total'
         90        OP_DATA                                                  $54
   35    91        FETCH_DIM_W                                      $55     !0, 'debts'
         92        FETCH_DIM_W                                      $56     $55, !3
         93        FETCH_DIM_W                                      $57     $56, 'invoices'
         94        ASSIGN_DIM                                               $57
         95        OP_DATA                                                  !2
         96      > JMP                                                      ->120
   38    97    >   INIT_ARRAY                                       ~61     0, 'id'
   39    98        ADD_ARRAY_ELEMENT                                ~61     0, 'debtReportId'
   40    99        FETCH_DIM_R                                      ~62     !2, 'currency'
        100        ADD_ARRAY_ELEMENT                                ~61     ~62, 'currency'
   41   101        FETCH_DIM_R                                      ~63     !2, 'total'
        102        ADD_ARRAY_ELEMENT                                ~61     ~63, 'total'
   38   103        ADD_ARRAY_ELEMENT                                ~61     null, 'dateCreated'
   45   104        INIT_ARRAY                                       ~64     0, 'id'
   46   105        FETCH_DIM_R                                      ~65     !2, 'id'
        106        ADD_ARRAY_ELEMENT                                ~64     ~65, 'number'
   47   107        FETCH_DIM_R                                      ~66     !2, 'date_created'
        108        ADD_ARRAY_ELEMENT                                ~64     ~66, 'issueDate'
   48   109        FETCH_DIM_R                                      ~67     !2, 'payment_due'
        110        ADD_ARRAY_ELEMENT                                ~64     ~67, 'paymentDate'
   49   111        FETCH_DIM_R                                      ~68     !2, 'total'
        112        ADD_ARRAY_ELEMENT                                ~64     ~68, 'total'
   50   113        FETCH_DIM_R                                      ~69     !2, 'left_to_pay'
        114        ADD_ARRAY_ELEMENT                                ~64     ~69, 'leftToPay'
        115        INIT_ARRAY                                       ~70     ~64
        116        ADD_ARRAY_ELEMENT                                ~61     ~70, 'invoices'
   37   117        FETCH_DIM_W                                      $59     !0, 'debts'
        118        ASSIGN_DIM                                               $59
   50   119        OP_DATA                                                  ~61
   26   120    > > JMP                                                      ->59
        121    >   FE_FREE                                                  $38
   57   122        UNSET_DIM                                                !0, 'invoices'
   59   123        INIT_FCALL                                               'json_encode'
        124        SEND_VAR                                                 !0
        125        DO_ICALL                                         $71     
        126        ECHO                                                     $71
        127      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
279.67 ms | 1412 KiB | 24 Q