3v4l.org

run code in 300+ PHP versions simultaneously
<?php function xml_encode($mixed, $domElement=null, $DOMDocument=null) { if (is_null($DOMDocument)) { $DOMDocument =new DOMDocument; $DOMDocument->formatOutput = true; xml_encode($mixed, $DOMDocument, $DOMDocument); echo $DOMDocument->saveXML(); } else { if (is_array($mixed)) { foreach ($mixed as $index => $mixedElement) { if (is_int($index)) { if ($index === 0) { $node = $domElement; } else { $node = $DOMDocument->createElement($domElement->tagName); $domElement->parentNode->appendChild($node); } } else { $plural = $DOMDocument->createElement($index); $domElement->appendChild($plural); $node = $plural; if (!(rtrim($index, 's') === $index)) { $singular = $DOMDocument->createElement(rtrim($index, 's')); $plural->appendChild($singular); $node = $singular; } } xml_encode($mixedElement, $node, $DOMDocument); } } else { $mixed = is_bool($mixed) ? ($mixed ? 'true' : 'false') : $mixed; $domElement->appendChild($DOMDocument->createTextNode($mixed)); } } } $str = xml_encode( array ( 'cry_shop' => array ( 'packs' => array ( 3 => array ( 'id' => 3, 'minLevel' => 1, 'elements' => array ( 'crystal' => array ( 'count' => 100, 'offer' => NULL, 'probability' => NULL, 'offerVal' => NULL, 'offerStartTime' => NULL, 'offerEndTime' => NULL, ), ), 'inapSystemName' => 'inap1', 'priceCraft' => array ( ), 'priceCrystal' => NULL, 'crystalOffer' => NULL, 'crystalOfferVal' => NULL, 'crystalOfferStartTime' => NULL, 'crystalOfferEndTime' => NULL, 'translationTitle' => NULL, 'translationDescription' => NULL, ), ), 'translationTitle' => NULL, 'translationDescription' => NULL, ), 'gold_shop' => array ( 'packs' => array ( 2 => array ( 'id' => 2, 'minLevel' => 1, 'elements' => array ( 'gold' => array ( 'count' => 500, 'offer' => NULL, 'probability' => NULL, 'offerVal' => NULL, 'offerStartTime' => NULL, 'offerEndTime' => NULL, ), ), 'inapSystemName' => 'inap1', 'priceCraft' => array ( ), 'priceCrystal' => NULL, 'crystalOffer' => NULL, 'crystalOfferVal' => NULL, 'crystalOfferStartTime' => NULL, 'crystalOfferEndTime' => NULL, 'translationTitle' => NULL, 'translationDescription' => NULL, ), ), 'translationTitle' => NULL, 'translationDescription' => NULL, ), 'res_shop' => array ( 'packs' => array ( 1 => array ( 'id' => 1, 'minLevel' => 1, 'elements' => array ( 'wood' => array ( 'count' => 30, 'offer' => NULL, 'probability' => NULL, 'offerVal' => NULL, 'offerStartTime' => NULL, 'offerEndTime' => NULL, ), 'stone' => array ( 'count' => 50, 'offer' => NULL, 'probability' => NULL, 'offerVal' => NULL, 'offerStartTime' => NULL, 'offerEndTime' => NULL, ), ), 'inapSystemName' => NULL, 'priceCraft' => array ( ), 'priceCrystal' => NULL, 'crystalOffer' => NULL, 'crystalOfferVal' => NULL, 'crystalOfferStartTime' => NULL, 'crystalOfferEndTime' => NULL, 'translationTitle' => NULL, 'translationDescription' => NULL, ), ), 'translationTitle' => NULL, 'translationDescription' => NULL, ), 'util_shop' => array ( 'packs' => array ( 4 => array ( 'id' => 4, 'minLevel' => 0, 'elements' => array ( 'dropRequestCounter' => array ( 'count' => 1, 'offer' => NULL, 'probability' => NULL, 'offerVal' => NULL, 'offerStartTime' => NULL, 'offerEndTime' => NULL, ), ), 'inapSystemName' => NULL, 'priceCraft' => array ( ), 'priceCrystal' => 5, 'crystalOffer' => NULL, 'crystalOfferVal' => NULL, 'crystalOfferStartTime' => NULL, 'crystalOfferEndTime' => NULL, 'translationTitle' => NULL, 'translationDescription' => NULL, ), ), 'translationTitle' => NULL, 'translationDescription' => NULL, ), ) ); var_dump($str);

preferences:
44.76 ms | 402 KiB | 5 Q