3v4l.org

run code in 300+ PHP versions simultaneously
<?php $content = json_decode('{"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":"Wroc\u0142aw","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 git.master, git.master_jit, rfc.property-hooks
{"transId":"655354-1","debtorCompany":{"nip":"1112223334","zipCode":"21-222","city":"Wroc\u0142aw","name":"RST test12 15 52","address":"chabrowa 4 kilka faktur bez plikow 1 waluta","countryCode":"PL","email":"test1@truckx.eu","phone":"1234567"},"attachments":[],"debts":[{"id":0,"debtReportId":0,"currency":"PLN","total":"56155.00","dateCreated":null,"invoices":[{"id":0,"number":"1111444","issueDate":"2015-06-01T00:00:00","paymentDate":"2015-06-22T00:00:00","total":"55555","leftToPay":"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"}]}]}

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
54.01 ms | 403 KiB | 8 Q