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);
Output for 8.3.0 - 8.3.4, 8.3.6
Warning: Trying to access array offset on null in /in/TGRpT on line 6 Warning: Trying to access array offset on null in /in/TGRpT on line 8 Warning: Trying to access array offset on null in /in/TGRpT on line 8 Warning: Trying to access array offset on null in /in/TGRpT on line 9 Warning: Trying to access array offset on null in /in/TGRpT on line 9 Warning: Trying to access array offset on null in /in/TGRpT on line 10 Warning: Trying to access array offset on null in /in/TGRpT on line 10 Warning: Trying to access array offset on null in /in/TGRpT on line 11 Warning: Trying to access array offset on null in /in/TGRpT on line 11 Warning: Trying to access array offset on null in /in/TGRpT on line 12 Warning: Trying to access array offset on null in /in/TGRpT on line 12 Warning: Trying to access array offset on null in /in/TGRpT on line 13 Warning: Trying to access array offset on null in /in/TGRpT on line 13 Warning: Trying to access array offset on null in /in/TGRpT on line 18 Warning: Trying to access array offset on null in /in/TGRpT on line 19 Warning: foreach() argument must be of type array|object, null given in /in/TGRpT on line 26 {"transId":null,"debtorCompany":{"nip":null,"zipCode":null,"city":null,"name":null,"address":null,"countryCode":null,"email":null,"phone":null},"attachments":null,"debts":[]}
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Trying to access array offset on null in /in/TGRpT on line 6 Warning: Trying to access array offset on null in /in/TGRpT on line 8 Warning: Trying to access array offset on null in /in/TGRpT on line 8 Warning: Trying to access array offset on null in /in/TGRpT on line 9 Warning: Trying to access array offset on null in /in/TGRpT on line 9 Warning: Trying to access array offset on null in /in/TGRpT on line 10 Warning: Trying to access array offset on null in /in/TGRpT on line 10 Warning: Trying to access array offset on null in /in/TGRpT on line 11 Warning: Trying to access array offset on null in /in/TGRpT on line 11 Warning: Trying to access array offset on null in /in/TGRpT on line 12 Warning: Trying to access array offset on null in /in/TGRpT on line 12 Warning: Trying to access array offset on null in /in/TGRpT on line 13 Warning: Trying to access array offset on null in /in/TGRpT on line 13 Warning: Trying to access array offset on null in /in/TGRpT on line 18 Warning: Trying to access array offset on null in /in/TGRpT on line 19 Warning: foreach() argument must be of type array|object, null given in /in/TGRpT on line 26 {"transId":null,"debtorCompany":{"nip":null,"zipCode":null,"city":null,"name":null,"address":null,"countryCode":null,"email":null,"phone":null},"attachments":null,"debts":[]}
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Warning: Trying to access array offset on value of type null in /in/TGRpT on line 6 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 8 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 8 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 9 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 9 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 10 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 10 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 11 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 11 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 12 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 12 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 13 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 13 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 18 Warning: Trying to access array offset on value of type null in /in/TGRpT on line 19 Warning: foreach() argument must be of type array|object, null given in /in/TGRpT on line 26 {"transId":null,"debtorCompany":{"nip":null,"zipCode":null,"city":null,"name":null,"address":null,"countryCode":null,"email":null,"phone":null},"attachments":null,"debts":[]}
Output for 7.4.0 - 7.4.33
Notice: Trying to access array offset on value of type null in /in/TGRpT on line 6 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 8 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 8 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 9 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 9 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 10 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 10 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 11 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 11 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 12 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 12 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 13 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 13 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 18 Notice: Trying to access array offset on value of type null in /in/TGRpT on line 19 Warning: Invalid argument supplied for foreach() in /in/TGRpT on line 26 {"transId":null,"debtorCompany":{"nip":null,"zipCode":null,"city":null,"name":null,"address":null,"countryCode":null,"email":null,"phone":null},"attachments":null,"debts":[]}
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Warning: Invalid argument supplied for foreach() in /in/TGRpT on line 26 {"transId":null,"debtorCompany":{"nip":null,"zipCode":null,"city":null,"name":null,"address":null,"countryCode":null,"email":null,"phone":null},"attachments":null,"debts":[]}
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/TGRpT on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/TGRpT on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/TGRpT on line 5
Process exited with code 255.

preferences:
303.39 ms | 401 KiB | 459 Q