3v4l.org

run code in 300+ PHP versions simultaneously
<?php function pathify($array, $path, &$output = []){ // declare $output as an empty array by default and modify by reference foreach($array as $k => $v){ if (is_array($v)) { // if can recurse pathify($v, "$path/$k", $output); // append key to path, access $v array }else{ $output[] = "$path/$k - $v"; // push completed string to output array } } return $output; // return array of path strings } $json='{ "name":{ "first_name":"James", "last_name":"Bond" }, "aliases":["007","Bond"], "profiles":[{"0":"unknown"},"007",{"2":"secret agent"}] }'; $data = json_decode($json, true); // decode json to an array echo implode("\n", pathify($data, "/Bond1")); // separate the returned string with a newline echo "\n-------\n"; echo implode("\n", pathify([], "/Bond2")); // separate the returned string with a newline echo "\n-------\n"; echo implode("\n", pathify([], "/Bond3")); // separate the returned string with a newline echo "\n-------\n"; echo implode("\n", pathify($data, "/Bond4")); // separate the returned string with a newline echo "\n-------\n"; echo implode("\n", pathify($data, "/Bond5")); // separate the returned string with a newline
Output for git.master, git.master_jit, rfc.property-hooks
/Bond1/name/first_name - James /Bond1/name/last_name - Bond /Bond1/aliases/0 - 007 /Bond1/aliases/1 - Bond /Bond1/profiles/0/0 - unknown /Bond1/profiles/1 - 007 /Bond1/profiles/2/2 - secret agent ------- ------- ------- /Bond4/name/first_name - James /Bond4/name/last_name - Bond /Bond4/aliases/0 - 007 /Bond4/aliases/1 - Bond /Bond4/profiles/0/0 - unknown /Bond4/profiles/1 - 007 /Bond4/profiles/2/2 - secret agent ------- /Bond5/name/first_name - James /Bond5/name/last_name - Bond /Bond5/aliases/0 - 007 /Bond5/aliases/1 - Bond /Bond5/profiles/0/0 - unknown /Bond5/profiles/1 - 007 /Bond5/profiles/2/2 - secret agent

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:
34.8 ms | 407 KiB | 5 Q