3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MySimpleXMLElement extends SimpleXMLElement { public function appendXML($append) { if ($append) { if (strlen(trim((string)$append)) == 0) { $xml = $this->addChild($append->getName()); } else { $xml = $this->addChild($append->getName(), (string)$append); } var_dump($append); foreach ($append as $child) { $xml->appendXML($child); } foreach ($append->attributes() as $n => $v) { $xml->addAttribute($n, $v); } } } } $currentPayment = new SimpleXMLElement('<payment></payment>'); $currentPayment->addChild('creditCard'); $currentPayment->creditCard->addChild('cardNumber', 'XXXX0027'); $currentPayment->creditCard->addChild('expirationDate', 'XXXX'); $paymentProfile = new MySimpleXMLElement('<paymentProfile></paymentProfile>'); $paymentProfile->appendXML($currentPayment); echo $paymentProfile->asXML();

preferences:
33.16 ms | 402 KiB | 5 Q