3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_to_xml(array $data) { $document = new DOMDocument(); array_to_xml_aux($data, $document); $document->formatOutput = true; return $document; } function array_to_xml_aux(array $data, DOMNode $parent, $name = null) { foreach ($data as $key => $value) { if ($key[0] == '@') { $parent->setAttribute( substr($key, 1), $value ); return; } if (is_numeric($key)) { $key = $name; } if (is_array($value)) { $subnode = new DOMElement($key); $parent->appendChild($subnode); array_to_xml_aux($value, $subnode, $key); } else { $xml_data->appendChild(new DOMElement($key, $value)); } } } $document = array_to_xml( array( 'Products' => array( 'Product' => array('@name' => 'TR-501'), 'Descricao' => array('@text' => '55.180.198 / 46789771'), 'Detalhes' => array( 'Variacao' => array( array( '@modelo' => 'Palio', '@ano' => '2006', '@motor' => '1.0 FIRE 8V (FLEX)', ), array( '@modelo' => 'Palio2', '@ano' => '2007', '@motor' => '1.0 FIRE 9V (FLEX)', ), ) ), ) ) ); echo $document->saveXML();
Output for git.master_jit, git.master
Warning: Trying to access array offset on value of type int in /in/78Pjl on line 13 Warning: Trying to access array offset on value of type int in /in/78Pjl on line 13 <?xml version="1.0"?> <Products> <Product name="TR-501"/> <Descricao text="55.180.198 / 46789771"/> <Detalhes> <Variacao> <Variacao modelo="Palio"/> <Variacao modelo="Palio2"/> </Variacao> </Detalhes> </Products>
Output for rfc.property-hooks
Warning: Trying to access array offset on int in /in/78Pjl on line 13 Warning: Trying to access array offset on int in /in/78Pjl on line 13 <?xml version="1.0"?> <Products> <Product name="TR-501"/> <Descricao text="55.180.198 / 46789771"/> <Detalhes> <Variacao> <Variacao modelo="Palio"/> <Variacao modelo="Palio2"/> </Variacao> </Detalhes> </Products>

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