3v4l.org

run code in 500+ PHP versions simultaneously
<?php function array_to_xml( $data, &$xml_data ) { foreach( $data as $key => $value ) { foreach($value as $innerkey => $innervalue) { $v = $innervalue['@value']; $t = ""; if(isset($innervalue['@attributes']['typ'])) { $t = $innervalue['@attributes']['typ']; } $kontakt = $xml_data->addChild('kontakt', $v); $kontakt->addAttribute('typ', $t); } } } $data = array("kontakt"=>[ 1=>[ '@value' => 'abc@abc.pl', '@attributes' => ['typ' => 'email'], ], 2=>[ '@value' => '3123453141', '@attributes' => ['typ' => 'telefon'], ], ] ); $xml_data = new SimpleXMLElement('<test></test>') ; array_to_xml($data,$xml_data); echo $xml_data->asXML();
Output for git.master, git.master_jit, rfc.property-hooks
<?xml version="1.0"?> <test><kontakt typ="email">abc@abc.pl</kontakt><kontakt typ="telefon">3123453141</kontakt></test>

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:
65.42 ms | 873 KiB | 4 Q