3v4l.org

run code in 300+ PHP versions simultaneously
<?php // take the badly formatted JSON $result = '{ "price": [ { "price": "2000", "origin_name": "JPN", }, { "price": "5000", "origin_name": "USA", } ] }'; // and remove the superfluous commas: $pat = "/(o.+),/"; $replace = "$1"; $nu_result = preg_replace($pat,$replace,$result); // now convert JSON into PHP array and traverse it $resultDecoded = json_decode($nu_result, true); $arr = array_pop($resultDecoded); array_walk_recursive($arr,function($e,$i) { if ($i == "price") { echo "price: ",$e,"\n"; } else if ($i == "origin_name") { echo "origin_name: ",$e,"\n\n"; } });
Output for git.master, git.master_jit, rfc.property-hooks
price: 2000 origin_name: JPN price: 5000 origin_name: USA

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:
35.33 ms | 405 KiB | 5 Q