3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myArray = array( 'Europe' => 'World', 'Asia' => 'World', 'Africa' => 'World', 'France' => 'Europe', 'Poland' => 'Europe', 'Germany' => 'Europe', 'Paris' => 'France', 'Lille' => 'France', 'Warsaw' => 'Poland', 'Szczecin' => 'Poland', 'Berlin' => 'Germany', 'Gumience' => 'Szczecin' ); $x = new SimpleXMLElement ("<root/>"); foreach ($myArray as $child => $parent) { if (!$x->xpath ("//$parent")) { $x->addChild($parent); } $x->xpath ("//$parent")[0]->addChild($child); } $json = json_encode($x); $array = json_decode($json,TRUE); var_export ($array);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'World' => array ( 'Europe' => array ( 'France' => array ( 'Paris' => array ( ), 'Lille' => array ( ), ), 'Poland' => array ( 'Warsaw' => array ( ), 'Szczecin' => array ( 'Gumience' => array ( ), ), ), 'Germany' => array ( 'Berlin' => array ( ), ), ), 'Asia' => array ( ), 'Africa' => array ( ), ), )

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:
44.81 ms | 402 KiB | 8 Q