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; }
Output for git.master_jit, git.master, rfc.property-hooks
INSERT INTO mytable (TheDate, Value1, Value2) VALUES ('2018-08-02',145,258); INSERT INTO mytable (TheDate, Value1, Value2) VALUES ('2018-08-03',428,528); INSERT INTO mytable (TheDate, Value1, Value2) VALUES ('2018-08-04',727,514);

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:
24.62 ms | 406 KiB | 5 Q